• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1223
  • Last Modified:

JQuery - Get next fieldset item from DOM

How do I get from any of the links in the ul list to the fieldset after the list.

e.g.


 $("#a.advancedLink").click(function()
{

   //$(this).next("fieldset").toggle(); //this does not traverse the following fieldset

});


At moment, the link will simply turn off/on the form fieldset.

<div class="searchFilterBy">
    <ul>
        
        <li><a class="searchLink" href="#">Search</a></li>
        <li><a class="filterLink" href="#">Filter By</a></li>
        <li><a class="advancedLink" href="#">Advanced Search</a></li>
    
    </ul>
    <fieldset>

Open in new window

0
smacca
Asked:
smacca
  • 2
  • 2
2 Solutions
 
David S.Commented:
Use the parent function:
$("#a.advancedLink").click(function()
{
 
   $(this).parent('ul').get(0).next("fieldset").toggle(); //this does not traverse the following fieldset
 
});

Open in new window

0
 
smaccaAuthor Commented:
Still doesn't work - is the 'get(0)' necessary??
Is there any way you can alert() the content of the tag you have grabbed - this would help with testing and debugging as I could see what I am getting with each command.

Thanks for your time.
0
 
David S.Commented:
I'm pretty sure the get(0) is necessary.

The jQuery Documentation is a useful reference: http://docs.jquery.com/Main_Page

For testing, you can do this:
$("#a.advancedLink").click(function()
{
 
   alert($(this).parent('ul').get(0).html());
}

Open in new window

0
 
smaccaAuthor Commented:
   $("a.searchLink, a.filterLink, a.advancedLink").click(function()
    {
        $(this).parent('li').parent('ul').next("fieldset").toggle();
    });

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now