Select items that do not have specific words in their class attribute.

How to select only <a>elements that do not have the word gallery inside the id or class attribute ? p>

+3
source share
4 answers

Try this selector:

a:not([id*=gallery], [class*=gallery])

This will select every element athat does not have a "gallery" in its value idor its classatttribute.

Or for the full ID or class name:

a:not([id=gallery], [class~=gallery])

This will select every item athat does not have a "gallery" as its identifier or class name.

+10
source

:

$('a').each(function(){
  if ($(this).attr('class').indexOf('gallery') == -1 && $(this).attr('id').indexOf('gallery') == -1) { 
    // your code....
  }
});
+1

not() http://api.jquery.com/not/

$("a").not(document.getElementById('gallery'))
+1

jquery hasClass, . .

check only class

$('a').each(function(){
if (!$(this).hasClass('gallery'))
  {
       //code here
  }
}); 

or check both class and id

$('a').each(function(){
if (!$(this).hasClass('gallery') && $(this).attr('id').indexOf('gallery') == -1)
  {
       //code here
  }
});
+1
source

Source: https://habr.com/ru/post/1755144/


All Articles