I want to do something with var p:
var p = $("li:last");
But I don't want to do anything if there is a certain Class appended. I tried :not like this:
var p = $("li:last:not(.Class)");
This doesn't work. How can I exclude .Class in my var?
Use the classList. contains() method to check if an element does not have a specific class, e.g. if (! el. classList.
jQuery :not() SelectorThe :not() selector selects all elements except the specified element. This is mostly used together with another selector to select everything except the specified element in a group (like in the example above).
To select element that does not have specific class with JavaScript, we can use the document. querySelector method with the :not pseudoclass. const li = document. querySelector("li:not(.
$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.
var p = $("li:last").not(".Class");
http://api.jquery.com/not/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With