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

Total Post:96

Points:676
Posted on    May-09-2013 4:48 AM

 JQuery JQuery 
Ratings:


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


AVADHESH PATEL

Total Post:604

Points:4228
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.

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

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

Follow MindStick