jQuery not() by element inside <div>

Description

jQuery not() by element inside <div>

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p").not($("div p.intro")).css("background-color", "yellow");
});//from  w w w. j  av a2s  . co m
</script>
</head>
<body>

<div style="border:1px solid black;">
  This is a div element
  <h1>Welcome to My Homepage</h1>
  <p>This is a test.</p>
  <p class="intro">I am from java2s.com.</p>
  <p>This is another test.</p>
</div>

<p class="intro">This p element is outside the div element.</p>
<p>This p element is also outside the div element.</p>

</body>
</html>



PreviousNext

Related