I need to select all the elements in my container except for a particular child element and its descendants.
In the following example I want My name is Donald
and I am a duck
to be excluded by the jQuery that highlights everything else in the container
div.
The issue is that the selector .container :not(.intro)
seems to only exclude My name is Donald
. Is there a way to do this?
$(document).ready(function() {
$(".container :not(.intro)").css("background-color", "yellow");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<h1>Welcome to My Homepage</h1>
<div class="container">
<div class="intro">My name is Donald
<div>I am a duck</div>
</div>
<div>I live in Duckburg.</div>
<div>My best friend is Mickey.</div>
</div>