[英]Jquery - How to find an element using class and attribute
I am trying to figure out the most efficient way to find my element. 我试图找出找到我元素的最有效方法。 Following i smy structure: 继我的smy结构:
<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
. 通过放入空格,你将它变成一个后代选择器,它找到匹配[customattrib='2']
所有元素,并且位于匹配div.a
的元素内 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.