WHAT ARE THE ALTERNATE WAYS TO FIND NEXT().NEXT() IN JQUERY

ben reitman

Total Post:96

Points:676
Posted by  ben reitman
JQuery 
 1756  View(s)
Ratings:
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>
        <li> <a href="#"> Designer </a> 
        </li>
        <li class="last"> <a href="#"> Screen Printed </a> 
        </li>
    </ul>
</li>

Advance thanks!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: What are the alternate ways to find next().next() in jquery

    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!

  1. Vijay Shukla

    Post:100

    Points:700
    Re: What are the alternate ways to find next().next() in jquery

    Hi!

    Try with .siblings selector:

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

    Or by index:

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!