I want to select all div parents using jQuery that don't have children with class locked
locked
Code example:
<div class='myparent'> <div class='mychild locked'></div> </div> <div class='myparent'> <div class='mychild locked'></div> </div> <div class='myparent'> <div class='mychild'></div> </div>
I feel very close:
$('div.myparent:not(:has(div[class=locked]))')
But that does not work.
You can just use the class selector, no DEMO attribute selector needed
$('.myparent:not(:has(div.locked))')
Note: you can do this too: - $('.myparent:not(:has(.locked))')
$('.myparent:not(:has(.locked))')
$(".mychild:not(.locked)").parent().css("color","red")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='myparent'> <div class='mychild locked'>1</div> </div> <div class='myparent'> <div class='mychild locked'>2</div> </div> <div class='myparent'> <div class='mychild'>3</div> </div>
jquery filter filter myparent, locked :
jquery filter
filter
myparent
$('.myparent').filter(function(){ return !$(this).find('.locked').length; }).css('color','blue');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='myparent'> <div class='mychild locked'>one</div> </div> <div class='myparent'> <div class='mychild locked'>two</div> </div> <div class='myparent'> <div class='mychild'>three</div> </div>
Source: https://habr.com/ru/post/1683000/More articles:Specify description-Content-Type in Pypi upload for markdown README - pythonThe logic behind OS O Background service restrictions - androidExecution failed for task ': react-native-fbsdk: compileReleaseJavaWithJavac' - androidDefault Specialization with Multiple Conditions - c ++Unexpected error annotations are everywhere since I installed the version of Oxygen - eclipseHow to split one Angular file into client, server and shared files? - angularUnable to declare static constexpr char [] - c ++How to integrate testcafejs in jenkins with different browsers - testingOwin: OnApplyRedirect вызывается несколько раз и создает неверный RedirectUri - c#Failed to execute linke command in response native application using reactive -base-firebase - xcodeAll Articles