Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "if not class" jQuery selector?

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?

like image 545
Youss Avatar asked Apr 18 '12 19:04

Youss


People also ask

How do you check if an element doesn't have a class?

Use the classList. contains() method to check if an element does not have a specific class, e.g. if (! el. classList.

How do I select not this in jQuery?

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).

How do you select an element that does not have a specific class?

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(.

What is $$ in jQuery?

$ 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.


1 Answers

var p = $("li:last").not(".Class"); 

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

like image 75
bhamlin Avatar answered Sep 29 '22 08:09

bhamlin