Reputation: 1733
How can I modify my code that affects all the elements with the same class In my Jquery to make click effects only to my desired html element (.divCollapsilble)
This is my site that shows the effect of my code below
My script.js:
// JavaScript Document
$(document).ready(function(){
$('.divCollapsible').hide();
$('.divToggle').click(function(){
var location = $(this).parent().parent();
$('.divCollapsible').slideToggle('slow');
});
});
How can I implement
Upvotes: 1
Views: 2427
Reputation: 26969
Change the code like this
$(document).ready(function(){
$('.divCollapsible').hide();
$('.divToggle').click(function(){
$(this).next(".divCollapsible").slideToggle('slow');
});
});
Upvotes: 5
Reputation: 3717
$(this).siblings('.divCollapsible').slideToggle('slow');
should do. That way you are targeting only siblings of your .divToggle
with class .divCollapsible
instead of all collapsible elements on the page.
Upvotes: 3