Select previous element using jquery selector only

Posted by  ben reitman
 2998  View(s)
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>

My Jquery line of code:

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

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. 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.