Home > DeveloperSection > Forums > Select previous element using jquery selector only
ben reitman
ben reitman

Total Post:96

Posted on    May-09-2013 4:48 AM

 JQuery JQuery 

 1 Reply(s)
 2090  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! 


Total Post:604

Posted on    May-09-2013 8:07 AM

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.


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

Follow MindStick