Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
In console, I have this error. I use the latest jquery 3.1.
How to rectify this element ?
Thank you
typeError: window.on is not a function
<script>(window).on('load', function (){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script>
You need to use $ as a prefix to the (window) part of your script or it won't be a JQuery object.
<script>$(window).on('load', function (){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script>
You're missing the $ symbol at the start of your code, this is the shorthand for jQuery and needs to be used when using any of the jQuery library. Your complete code becomes:
$(window).load(function() {
var maxHeight = 0;
$(".equal-height").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".equal-height").height(maxHeight);
};
This is also the same as
jQuery(window).load(function() {
var maxHeight = 0;
$(".equal-height").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".equal-height").height(maxHeight);
};
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a script (config.js) at the base of every page. But, that script contains code that isn't used on every page. The console returns unused or undeclared variables as undefined.
let currentURL = document.location.href;
function redirectURL() {
if (currentURL.indexOf('dogs.html') > -1) {
redirect.innerHTML = `Cats`;
} else {
redirect.innerHTML = `Dogs`;
}
}
redirectURL();
This is what's returned.
How do I fix this?
You need to check whether the redirect element exists before trying to use it.
function redirectURL() {
if (typeof redirect == 'undefined') {
return;
}
if (currentURL.indexOf('dogs.html') > -1) {
redirect.innerHTML = `Cats`;
} else {
redirect.innerHTML = `Dogs`;
}
}
This will allow the function to work without error on pages that don't define redirect.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This is happening on an angular application I'm building. If a user enters 80 into an HTML input, it always seems to get this comparison wrong.
var x = '80';
var y = 150.9800;
/* Returns incorrect answer */
if (parceFloat(x) < y) {
return true;
} else {
return false;
}
You need to use ParseFloat() not parceFloat() ...
parceFloat is not an existing function.
parceFloat() is not a function, the function is parseFloat()
A simple typo is all the error there is.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm writing a simple jquery code to animation an element on my page:
curent
$('#tgs-nav-icon').on('click', function() {
var $nav = (".canvas-menu-content");
var bounceInRight = "bounceInRight animated";
if(! $nav.hasClass(bounceInRight) ) {
$nav.addClass(bounceInRight);
}
else {
$nav.removeClass(bounceInRight);
}
});
Uncaught TypeError: nav.hasclass is not a function
I tried testing this to see where I went wrong and this code comes back false as it should:
var help = $( ".canvas-menu-content" );
console.log(help.hasClass("foo"));
I can't figure out why the if statement is throwing me the error.
I've tried doing some research, but none of the previous questions seem to answer my issue.
You're assigning $nav to the string ".canvas-menu-content" here:
var $nav = (".canvas-menu-content"); // $nav is now '.canvas-menu-content'
Assign it to a jQuery object instead:
var $nav = $(".canvas-menu-content"); // $nav is now a jQuery object containing all
// elements with class canvas-menu-content
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I found answers alluding to this question but most of them seemed to be based on jQuery. As an exercise I am building a image slider app in jQuery and then Javascript. I want to understand what jQuery is doing under the hood, and be able to make the decision to use it or not based on the project.
My problem is this: when I click the next button, I want the gallery to slide to the left, and prevImg will be removed, currentImg will become next and so forth. I will then add a li element with the appropriate class nextImg and the image.
Everything is working fine, but the line of code nextImg.appendChild(next_ImgPath) is not appending an image.
function slideAnimSetting(direction) {
counterAction();
if (direction == 1) {
establishImgPaths();
for (var i = 0; i < innerListEl.length; i++) {
leftPosition = innerListEl[i].offsetLeft;
topPosition = innerListEl[i].offsetTop;
Tween.to(innerListEl[i], 1, {left: leftPosition-700});
}; // end for
prevImg.removeAttribute('class');
currentImg.className = 'prevImg';
nextImg.className = 'currentImg';
listEle = document.createElement('li');
listEle.className = 'nextImg';
for (var i = 0; i < innerUlEl.length; i++) {
innerUlEl[i].appendChild(listEle);
}; //end for
nextImg = document.getElementsByClassName('next-img');
nextImg = nextImg[0];
nextImg.appendChild(next_ImgPath);
setImageStyles();
}
}; // end slideAnimSetting
The console.log is telling me that nextImg is undefined.
You gave it a className of nextImg, but you're searching for next-img.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Here is a bit of non-working JavaScript code:
function clientEventsManager(io) {
this.connectedClients = 0;
this.createEventReceivers = function(io) {
io.sockets.on('connection', function(socket) {
this.connectedClients++;
//does not increase "connectedClients" of "clientEventsManager" function
}
}
createEventReceivers(io); //it is the only call to createEventReceivers()
}
var Manager = new clientEventsManager(io); //it is the only instanciation of clientEventsManager
My question is: Is there a way to change clientEventsManager.connectedClients in clientEventsManager.createEventReceivers()?
EDIT: this post is a duplicate of this one, thank's for answering
Quick and dirty solution
function base(param) {
this.attr1 = "azertyuiop";
this.attr2 = 123;
this.attr3 = param;
var self=this;
this.fct1 = function() {
console.log("azerty keyboard first row: "+self.attr1);
//Doesn't work
}
}