jQuery Selector :has() select <div> with <p> and <span> inside

Description

jQuery Selector :has() select <div> with <p> and <span> inside

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(){
  $("div:has(p, span)").css("border", "solid red");
});//from ww w  . j a va  2 s.co m
</script>
</head>
<body>

<div>
  <p>This is a paragraph inside a div element.
    <span>This is a span element</span>
  </p>
</div>
<br>

<div>This is a div element with no p or span elements.</div>

</body>
</html>



PreviousNext

Related