Search code examples
jquerydom-traversal

How can I get the element below "this"


How do you get to the next node below this

For example

<ul id="secondary-nav">
    <li id="isOpen" class="expandable">
        <p>
            <ul style="display: none;">
    </li>
    <li id="isClosed" class="expandable expanded">
        <p>
            <ul style="display: none;">
    </li>
</ul>

Below is the running code:

$('#secondary-nav li').click(function() {
    var fstname = $(this).attr('class');
    alert(fstname);
    if (fstname == 'expandable') {
        if ($('#secondary-nav li').hasClass('expandable expanded')) {
            $('#secondary-nav li').removeClass('expanded');
            $('#secondary-nav li ul').css('display', 'none');
        }
    }
    $(this).addClass('expanded');
    //******************************//
    $(this).next('ul').css('')
});​

How would I get access to the <ul> element below this at //*********// to change the style of this element.


Solution

  • use find:

    $(this).find('ul');