Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <script src="../../ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").filter(function(){ return $("span",this).length==2;}).css("background-color","yellow"); }); </script> </head> <body> <div> <p>A p element <span>with one span element.</span></p> <p>A p element <span>with</span> two <span>span elements.</span></p> <p>A p element <span>with one span element.</span></p> <p>A p element <span>with</span> two <span>span elements.</span></p> <p>A p element with no span element.</p> </div> <p>This example returns all p elements that have two span elements. P elements with none, one, or more than two span elements, will not be returned.</p> </body> <!-- Mirrored from www.w3schools.com/jquery/tryit.asp?filename=tryjquery_traversing_filter_func by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:15:59 GMT --> </html>
Result:
Try it Yourself - © w3schools.com