仅使用jQuery选择器选择上一个元素 [英] Select previous element using jQuery selector only

查看:78
本文介绍了仅使用jQuery选择器选择上一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要使用jQuery 选择器来选择前一个元素。

I need to select the previous element using only a jQuery selector.

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

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

我想选择具有类 .hitarea 。我正在寻找类似 $(#devicelist:div.hitarea)的东西

I want to select div which has class .hitarea. I am looking for something like $("#devicelist:div.hitarea")

它应该只做使用jQuery的选择器

It should be done only with a selector of jQuery.

推荐答案

$('。hitarea')也是选择器。

$('.hitarea') is also a selector.

您可以将其用作选择器:

You can use this as a selector:

$('#devicelist,.hitarea')

这篇关于仅使用jQuery选择器选择上一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆