Superman Superman - 6 days ago 5
jQuery Question

I want to exclude some class from html use jquery, for exmple $('html').not('.classname'), but it did not work?

I want to exclude some class use jquery, for exmple $('html').not('.classname'), but it did not work? what's wrong?

Answer

Your current syntax is trying to select a html tag that doesn't have the given class.

You probably won't have a class on your html tag.

What you want might be

$('*:not(.className)')

This selects all the elements except the one's with that given class.

Alternatively you could use

$("*").not(".className")

which would not be recommendable performance-wise, since it would select all elements first, only then removing the ones not having that .className.

This selects all the elements (including head, body etc) except the one's with that given class.

This is not a efficient way to select elements.

It will be better if you be more specific in your selection like select all div elements with out this className.

$('div:not(.className)')

Or more specifically within a main div

$('#mainDivId div:not(.className)')