[jQuery] Re: DOM traversal -- need both parent node and siblings
No need for the .end() there. Plus you can use .andSelf() to include the first td and then run the addClass command just once. function() { $(this).parent().siblings().andSelf().addClass(inactive); } should do it. On Jun 11, 10:26 am, Kevin Major [EMAIL PROTECTED] wrote: Hello everyone, I'm currently in a bit of a bind. I have a checkbox that's within a table cell. I want it so when the input is clicked, the parent table cell AND its siblings change their classes. I can get to the parent element, but how would I attach this functionality to its siblings? Right now, I have: $(document.forms[Grid].elements[grid[]]).toggle(function() { $(this).parent().addClass(active);}, function() { $(this).parent().addClass(inactive); }); (I'm not using toggleClass because I have formatting within the inactive class that's different than some of the other elements) Would adding something like: .end().siblings().addClass(active); To the end of my statements remedy the issue?
[jQuery] Re: DOM traversal -- need both parent node and siblings
Great, thanks a bunch! On Jun 11, 3:05 pm, Happy [EMAIL PROTECTED] wrote: No need for the .end() there. Plus you can use .andSelf() to include the first td and then run the addClass command just once. function() { $(this).parent().siblings().andSelf().addClass(inactive); } should do it. On Jun 11, 10:26 am, Kevin Major [EMAIL PROTECTED] wrote: Hello everyone, I'm currently in a bit of a bind. I have a checkbox that's within a table cell. I want it so when the input is clicked, the parent table cell AND its siblings change their classes. I can get to the parent element, but how would I attach this functionality to its siblings? Right now, I have: $(document.forms[Grid].elements[grid[]]).toggle(function() { $(this).parent().addClass(active);}, function() { $(this).parent().addClass(inactive); }); (I'm not using toggleClass because I have formatting within the inactive class that's different than some of the other elements) Would adding something like: .end().siblings().addClass(active); To the end of my statements remedy the issue?- Hide quoted text - - Show quoted text -