如何仅在其id或class属性中选择<a>
元素没有单词库 ?
Try this selector:
a:not([id*=gallery], [class*=gallery])
This will select each a
element that does not have “gallery” in either its id
or its class
atttribute value.
Or for a full ID or class name match:
a:not([id=gallery], [class~=gallery])
This will select each a
element that does not have “gallery” as its ID or as a class name.
One way is to go about like this:
$('a').each(function(){
if ($(this).attr('class').indexOf('gallery') == -1 && $(this).attr('id').indexOf('gallery') == -1) {
// your code....
}
});
使用not()方法http://api.jquery.com/not/
$("a").not(document.getElementById('gallery'))
there is a hasClass selector in jquery you can use that. try this.
check for class only
$('a').each(function(){
if (!$(this).hasClass('gallery'))
{
//code here
}
});
or check for both class and id
$('a').each(function(){
if (!$(this).hasClass('gallery') && $(this).attr('id').indexOf('gallery') == -1)
{
//code here
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.