[英]jQuery get an element by its data-id
Similar to this question here , I'm looking to get an element based on it's data-id. 与此类似的问题在这里 ,我希望得到基于它的元素的数据-ID。
<a href="#" class="whatever" data-item-id="stand-out">...</a>
I'm looking to take action on the a tag. 我正在寻找对标签采取行动。 It has a shared class amongst many other elements and has no base id, just a data-item-id.
它在许多其他元素中有一个共享类,没有基本id,只是一个data-item-id。
Can the element be found by it's data-item-id or can I only find out what the data-item-id is? 可以通过它的data-item-id找到元素,还是只能找出data-item-id是什么?
$('[data-item-id="stand-out"]')
You can always use an attribute selector . 您始终可以使用属性选择器 。 The selector itself would look something like:
选择器本身看起来像:
a[data-item-id=stand-out]
是的,您可以通过数据属性找出元素。
element = $('a[data-item-id="stand-out"]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.