Not Class Selector in Jquery

Not class selector in jQuery

You need the :not() selector:

$('div[class^="first-"]:not(.first-bar)')

or, alternatively, the .not() method:

$('div[class^="first-"]').not('.first-bar');

How to write if not class jQuery selector?

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

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

jQuery select elements that do not contain a class

To do it just with a selector, you'd use :not with :has:

$(".hi:not(:has(.image))")
// or to be more specific:
$(".hi:not(:has(.hue > .image))")

Note that :has is jQuery-specific.

To do it with filter, you could use find in the callback:

$(".hi").filter(function() { return $(this).find(".image").length == 0; })
// or to be more specific:
$(".hi").filter(function() { return $(this).find(".hue > .image").length == 0; })

How can I select all elements without a given class in jQuery?

You can use the .not() method or :not() selector

Code based on your example:

$("ul#list li").not(".active") // not method
$("ul#list li:not(.active)") // not selector

If not class clicked

If it's supposed to work for all div elements, target all div elements (or whatever you like really), and check if it has the class or not inside the event handler :

$('div').on('click', function() {
if ( $(this).hasClass('whatever') ) {
alert("You clicked a div with the class");
} else {
alert("You clicked a div without the class");
}
});

How to ignore multiple classes using the :not selector?

The :not selector can take multiple CSS selectors as arguments ( http://api.jquery.com/not-selector ). E.g.

$('div:not(.a,.b)').empty()

http://jsfiddle.net/HFfcP/

Has no class name jquery selector

How about

$("div:not(.doneAnimated)")

Looking at the class property directly is a fragile programming practice. The class is a list, so checking for simple equality doesn't always work — and if it works today, it may not work after later changes.

If you need to check when your jQuery object is not formed by a selector, you can use .not():

$(this).not(".doneAnimated")

If you want to just test the state of this:

if (!$(this).is(".doneAnimated")) {
// do something
}

The .is() method returns true or false, while .not() acts like a filter on the jQuery object contents.

edit a comment points out that an alternative to the general-case .is() is .hasClass():

if (!$(this).hasClass("doneAnimated")) {
// do something
}

Note that with .hasClass() you pass in just the class name, without a leading ., a mistake I've made more than once.

How to Select Element That Does Not have Specific Class

This selects the second LI element.

document.querySelector("li:not([class])")

or

document.querySelector("li:not(.completed):not(.selected)")

Example:

// select li which doesn't have a 'class' attribute...console.log(document.querySelector("li:not([class])"))
// select li which doesn't have a '.completed' and a '.selected' class...console.log(document.querySelector("li:not(.completed):not(.selected)"))
 <ul id="tasks">    <li class="completed selected">One Task</li>    <li>Two Task</li>  </ul>

select input type next with not class selector

You do not have a text class assigned to your input element.

You can use the attribute selector:

$('input[type="text"]:not(.fld-required-' + val + ')').each(function() {
$(this).val('');
});

JQuery : Select an element with N clases and not class X

You can use selector like this $('div.a.b:not(.c)')

  1. div.a.b selects all div elements that have both classes a and b
  2. :not(.c) but won't select div element with class c

$('div.a.b:not(.c)').css('color', 'red')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div class='a b c'>Div</div><div class='a b'>Div</div>


Related Topics



Leave a reply



Submit