jQuery通过其data-id获取元素 [英] jQuery get an element by its data-id

查看:3526
本文介绍了jQuery通过其data-id获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于此问题此处,我正在寻找基于其数据ID的元素.

Similar to this question here, I'm looking to get an element based on it's data-id.

<a href="#" class="whatever" data-item-id="stand-out">...</a>

我希望对a标签采取行动.它具有许多其他元素之间的共享类,并且没有基ID,只有一个data-item-id.

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.

可以通过data-item-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?

推荐答案

您始终可以使用属性选择器.选择器本身看起来像:

You can always use an attribute selector. The selector itself would look something like:

a[data-item-id=stand-out]

这篇关于jQuery通过其data-id获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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