This presumably simple task resulted in much more scripting logic than I thought would be necessary.
Goal: when the user clicks a button inside one of the divs, it affects said div.
Issues: I did not wish to have my function target specific elements in my DOM. (ex. targeting <a> by ID). Also, because my function is traversing the DOM and being called in multiple instances, I had to use $(this) format so as not to be specific to one ID.
Anyways, here is my code:
$(".button").toggle(function(){
$(this).parent().children(".innerBox").fadeIn();
}, function(){
$(this).parent().children(".innerBox").fadeOut();
});
It works fine. However, can someone with a little more jQuery savvy please let me how I could execute this function in the future, without having to parse through siblings and making it more convoluted than need be?
$(this).siblings(".innerBox")...– Shmiddty Oct 16 '12 at 21:18.toggleClass('on') / .toggleClass('off')and addtransitionsto your CSS for the fade effect. – Kevin Boucher Oct 16 '12 at 21:20