How to select elements with jQuery that have a certain value in a data attribute array

你。 提交于 2019-12-13 08:47:57

问题


is there a way in jQuery to select elements that have a certain value in a data attribute array?

Consider this snippet of html:

<li id="person1" data-city="Boston, New York, San Fransisco">
    Person name 1
</li>
<li id="person1" data-city="Los Angeles, New York, Washington">
    Person name 2
</li>

What is the best way in jQuery to select all persons with "New York" in the data-city attribute?


回答1:


even though i don't see your html, it should be:

$('[data-city*="New York"]')


来源:https://stackoverflow.com/questions/7344353/how-to-select-elements-with-jquery-that-have-a-certain-value-in-a-data-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!