Same JS function — Many times?
-
19-09-2019 - |
Question
I previously got this (useful!) answer about using .next() for same DIV blind effect.
However, I can't seem to get this simple function to work for more than one DIV at the same time:
$(document).ready(function(){
$("#closeButton").click(function (){
$(this).next().toggle("fast");
});
});
Any ideas? Thanks.
Solution
The selector you are using is only selecting one element. You would need to change is to it selected a collection of elements.
$(document).ready(function(){
$(".wider_div h3").click(function (){
$(this).next().toggle("fast");
});
});
This might work given the structure.
OTHER TIPS
Is it about a specific type of button that occurs multiple times on a page? Try using jQuery's live()
:
$(document.ready(function() {
$('button.your_class').live('click', function (){
$(this).toggle('fast');
});
});
and attach the appropriate class to the buttons you want to 'be listened'.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow