Re: [jQuery] Traversing to next class?
On Tue, Feb 2, 2010 at 11:28 PM, Photonic tmlew...@gmail.com wrote: Now the problem I am having is with $(this).next ('.textDescription').hide(); . What am I doing wrong. I was under the impression that it would select the next object with the class of textDescription and hide it... but it isn't. You need to use nextAll(), not next(). http://api.jquery.com/next/ .next( [ selector ] ) Returns: jQuery Description: Get the immediately following sibling of each element in the set of matched elements, optionally filtered by a selector. http://api.jquery.com/nextAll/ .nextAll( [ selector ] ) Returns: jQuery Description: Get all following siblings of each element in the set of matched elements, optionally filtered by a selector. Nathan
[jQuery] Traversing to next class?
I am trying to toggle content based on toggling links. Here is the code: a href=# class=portLink Used id=description style=float: left;DESCRIPTION/a a href=# class=portLink id=specifications style=float: right;SPECIFICATIONS/a div class=textDescription style=clear: both;pTest 1/p/div div class=textSpecificationpTest 2/p/div Now when I click the link for Specifications, I want it to show the next specifications text and hide the description text. Same thing with Descriptions, only in reverse. Here is the code I have to do that: $('.textSpecification').hide(); $('.portLink').click(function() { if(!$(this).hasClass(Used)) { if($(this).attr('id') == description) { $(this).next().toggleClass(Used); $(this).next('.textDescription').show(); $(this).next('.textSpecification').hide(); } else { $(this).prev().toggleClass(Used); $(this).next('.textDescription').hide(); $(this).next('.textSpecification').show(); } $(this).toggleClass(Used); } }); Now the problem I am having is with $(this).next ('.textDescription').hide(); . What am I doing wrong. I was under the impression that it would select the next object with the class of textDescription and hide it... but it isn't.