jQuery的 - 如何找到使用类别和属性的元素 [英] Jquery - How to find an element using class and attribute

查看:170
本文介绍了jQuery的 - 如何找到使用类别和属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出最有效的方式找到我的元素。下面笔者SMY结构:

 < D​​IV CLASS =Acustomattrib =2>

为了找到这个元素,我可以做这样的事情:

  $(div.a [customattrib ='2'])

这似乎并没有工作,有另一种方式来做到这一点?

如果没有一流的,我能够得到的价值,但我不认为这是我的结构足够的效率:

  $(DIV [customattrib ='2'])


解决方案

删除空格:

  $(div.a [customattrib ='2'])

通过把在太空,你使之成为一个后代选择它找到匹配 [customattrib ='2'] 并的里面的所有元素的匹配元素 div.a

I am trying to figure out the most efficient way to find my element. Following i smy structure:

<div class="a" customattrib="2">

in order to find this element can I do something like :

$("div.a [customattrib='2']")

This does not seem to work, is there another way to do this?

Without the class I am able to get the value but I do not think this is efficient enough for my structure:

$("div [customattrib='2']")

解决方案

Remove the space:

$("div.a[customattrib='2']")

By putting in the space, you're making it into a descendant selector which finds all elements that match [customattrib='2'] and are inside an element that matches div.a.

这篇关于jQuery的 - 如何找到使用类别和属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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