在jQuery中查找具有特定属性值的所有元素
问题描述:
我需要找到所有具有特殊属性值的元素.
I need to find all elements that has a special attribute value.
这是我需要查找的div(我有很多.)
Here is the div I need to find (I have many of them..)
<div imageId='imageN'>...
我只需要遍历具有imageId='imageN'
答
$('div[imageId="imageN"]').each(function() {
// `this` is the div
});
要检查属性的唯一存在,无论使用哪个值,都可以使用选择器代替:$('div[imageId]')
To check for the sole existence of the attribute, no matter which value, you could use ths selector instead: $('div[imageId]')