I’m new to jQuery and Javascript. I’m trying to make a button that I can double click which then loops through all elements in the webpage with a certain class and fades them.
Currently, I’m trying this:
$(".fadeall").dblclick(function() {
$("div.section").each(function(idx,item) {
item.fadeTo(25,inactiveOpacity);
});
});
In my debugger I see the double click happening, but the function in the each call is not being triggered.
I’m believe I’m not matching the div.section elements correctly, but don’t know the correct approach.
Assuming the HTML has
<div>elements with the classsection, the only other thing I can see that you would need to do is wrapitemin a jQuery object.Since
itemis the DOM element, it needs to be wrapped with a jQuery object so that it will have access to methods like.fadeTo().Another approach is to use
thisin the.each(), which will refer to the DOM element as well.EDIT:
Also, make sure the DOM is loaded before your code runs:
This is a shortcut for jQuery’s
.ready()method, which will ensure that your code doesn’t run until the elements are available.