Home > DeveloperSection > Forums > What are the alternate ways to find next().next() in jquery
ben reitman
ben reitman

Total Post:96

Posted on    April-08-2013 2:30 AM

 JQuery JQuery 

 2 Reply(s)
 1740  View(s)
Rate this:
Hi All!

I want to change the css attribute of element which is just next to next of selector.

I have used this syntax

$('#hide').next().next().css('display', 'block');
but i think there can be another better approach can be use like find() or eq()

<li class="expandable">
    <div class="hitarea collapsable-hitarea"></div>
    <div id="hide" class="hide"></div>
    <a href="#" class=""> <strong>Stitched</strong> </a>

    <ul style="display: none;" id="hi">
        <li> <a href="#"> Hand Block Print </a> 
        <li> <a href="#"> Designer </a> 
        <li class="last"> <a href="#"> Screen Printed </a> 

Advance thanks!


Total Post:604

Posted on    April-08-2013 7:40 AM

Hi Ben!

You can try as following line of code!

$('#hide').nextAll().eq(1).css('display', 'block');

nextAll() returns all the next elements
eq(1) returns the second one amongst them.

Hope it helpful you!

Vijay Shukla

Total Post:100

Posted on    April-08-2013 8:04 AM


Try with .siblings selector:

$('#hide').siblings("ul").css('display', 'block');

Or by index:

$('#hide').siblings("ul").eq(0).css('display', 'block');

Don't want to miss updates? Please click the below button!

Follow MindStick