jQuery select a div with a certain class, that doesn't have another class
Use :not()
to exclude the other class:
$('.fuu:not(.no)')
Select a class except another class in jquery
you can use :not
selector
$(document).on('click', '.handle:not(.exception)', function (e) {
//I want to select only 2nd div.
});
or to select the 2nd .handle class element you can use :eq(1)
or nth-child(2)
'.handle:eq(1)' // index start from 0 so 1 to select 2nd one
'.handle:nth-child(2)' // index start from 1 so 2 to select 2nd one
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; })
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 can I select elements that don't have any of several classes using jQuery?
this should do it:
$('div.everyDiv:not(.hide1, .hide2, .hide3)').hide();
http://jsfiddle.net/s9uyk/
as per comments: making it a little more obvious what the fiddle is doing:
not it adds a class to all the ones that DON'T Have any of the hide classes.
http://jsfiddle.net/s9uyk/2/
jQuery select divs that dont have a class containing a particular word
use this:
$('#available-widgets-list div:not([class*="layers-widget"]')).addClass('hidden');
JQuery find a div with a certain classname and specific text
Using class selector and contains together, this should do
var childs = $(el).find("div.selected:contains('hello')");
How to select an element which doesn't have a specific class name, using jQuery?
$('a:not(.active)')
should work
yours works as well. just tested:
http://jsfiddle.net/UP6a7/
jQuery If DIV Doesn't Have Class x
Use the "not" selector.
For example, instead of:
$(".thumbs").hover()
try:
$(".thumbs:not(.selected)").hover()
jQuery select another element with certain class in same parent
Because there is n o parent with that class. You need find()
.
Actually you need to write
var ReturnedText = $(this).parent().find(".lookAtMe").text();
$("#button").on("click",function(){ var ReturnedText = $(this).parent().find(".lookAtMe").text(); console.log(ReturnedText); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id='parent'> <button id='button'></button> <div id='child'> <div id='grandchild' class='lookAtMe'> Some JSON text </div> </div></div>
Related Topics
React Animation for Moving an Element from One Parent to Another
Browser Support for Angular Material
JavaScript Style Property Is Empty
Stop Infinite CSS3 Animation and Smoothly Revert to Initial State
Get CSS Not-Computed Property-Value with JavaScript Only
Hover Effect Stays After Touch in Jquerymobile
How to Horizontal Scroll When Scrolling Vertical
How to Change Datatable Row Background Colour Based on the Condition in a Column, Rshiny
Bootstrap V3 - Opening a Modal Window Forces the Page to Scroll Up to the Top
Make Named Anchor Bookmarks Appear Always at Top of the Screen When Clicked
Attempt to Add a Rule to a CSS Stylesheet Gives "The Operation Is Insecure" in Firefox
How to Get New Image Size Dimension After Giving Object-Fit:Contain Property to the Image Tag
How to Measure the Space That a Text Will Take in JavaScript
Angularjs Bug in Ie with Style VS Ng-Style
JavaScript Style.Display="None" or Jquery .Hide() Is More Efficient
Creating a Custom Attribute with Angularjs