Select Last child with element inside - Javascript jQuery Selector

Javascript examples for jQuery Selector:nth-child

Description

Select Last child with element inside

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*  w w w  . j  ava2  s  .co m*/
$(function() {
    $('p:has(span)').last().css({ 'background': 'red' });
});
    });

      </script> 
 </head> 
 <body> 
  <div> 
   <p> <span>asdf</span> </p> 
   <p> <span>aaa</span> </p> 
   <p>aaa</p> 
  </div>  
 </body>
</html>

Related Tutorials