SELECT PREVIOUS ELEMENT USING JQUERY SELECTOR ONLY

ben reitman

Total Post:96

Points:676
Posted by  ben reitman
JQuery 
 2174  View(s)
Ratings:
Rate this:
Hi Guys!

How to select previous element using jquery selector 

My HTML Line of code:

<li class="collapsable">
                       <div class="hitarea collapsable-hitarea"></div>
                       <span id="devicelist" class="ankr">Device List</span>
                       <ul id="ultree">
                              <li type="dev" device="/dev/sdh1" id="dev0" class="litab">
                                    <img height="20px" width="20px" src="../Images/drive.png" class="dicon">
                                    <a class="ankr dn" href="#">'/dev/sdh1'</a>
                              </li>
                       </ul>
</li>

My Jquery line of code:

$(document).on("click","#devicelist,**Here Selector will be used**",this,function(event){
        console.log(this);
        console.log(event.target);
    });

I want to select div which has class name as "hitarea"

I want to something like $("#devicelist: Somethis here write to select div.hitarea")

It should be done only selector of jquery.

How can i do this?

Any succession will be welcome!

Thanks in advance! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Select previous element using jquery selector only

    Hi Ben!


    you can use the prev() selector

    Description: Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.

    $('#devicelist').prev();

Answer

NEWSLETTER

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