Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function () { $("button").click(function () { $("p").has('span').css("background-color", "yellow"); }); }); </script> </head> <body> <h1>jQuery DOM Traversing Methods: has()</h1> <p> This is paragraph without span. </p> <p> This is paragraph with <span>span.</span> </p> <button>Click Here to Test .has()</button> </body> </html>
Result: