Select div element who has p span and li - Javascript jQuery Selector

Javascript examples for jQuery Selector:has

Description

Select div element who has p span and li

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("div:has(p, span, li)").css("border", "solid red");
});//from ww w .ja  v  a 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>
  <li>This is a list item inside a div element</li>
</div>
<br>

<div>This is a div element.

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

</div>

</body>
</html>

Related Tutorials