Select div (or other element) that class contains “grap” (o other specified word) for example

浪尽此生 提交于 2019-12-04 22:50:38

Use the attribute contains selector:

$('div[class*="grap"]')

Depending on your particular use-case, you could try the attribute prefix selector:

var $grapDivs = $('div[class|="grap"]');

It seems from your sample data that "grap" is always prefixing the class, so if that's the case this may be what you want. If "grap" can be anywhere in the class instead of just at the beginning, use *= instead.

Use the "attribute contains" selector: http://api.jquery.com/attribute-contains-selector/
The "attribute contains word" selector won't work because, according to the docs, it finds elements where the specified attribute contains the given word delimited by spaces.

You want to use the "Attribute contains selector", not the "Attribute contains WORD selector", which is what you linked to.

What you're looking for is the "attribute contains selector"

See an example here http://jsfiddle.net/CsvUY/

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