Select all p elements that have span or b elements inside of them - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:has

Description

Select all p elements that have span or b elements inside of them

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(){
    $("p").has("b,span").css("background-color", "yellow");
});//from  w w  w .  j  av a2  s  . c  om
</script>
</head>
<body>

<p>My <span>name</span> is <span>name</span>.</p>
<p><span>span</span> live in <span>span</span>.</p>
<p><span>span</span> is <span>span</span>.</p>

<p><b>b</b> is <b>b</b>.</p>

</body>
</html>

Related Tutorials