Add a unique listener to all elements in a class
Is it possible via javascript or jQuery to add a unique event listener to
all elements of a class so that when an event is triggered is is triggered
for only that element and not all elements having the same class name?
For example, if I have the following HTML
<div class"clickable-box"><span style="display: none;">Hi There!</span></div>
<div class"clickable-box"><span style="display:
none;">Peek-A-Boo!</span></div>
<div class"clickable-box"><span style="display: none;">Now You See
Me!</span></div>
...and the following jQuery
$('.clickable-box').click(function() {
$('.clickable-box span').slideToggle('slow');
});
...the above will toggle the reveal the span for all the divs.
Is there a way to make these trigger individually without having to use a
unique id or class for each div?
No comments:
Post a Comment