Get the html of each p element, except the ones that contain an img element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:html

Description

Get the html of each p element, except the ones that contain an img element

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.4.4.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from   w ww  .jav  a  2s  .c  o  m
$('p:not(:has(img))').each(function(){
   console.log($(this).attr('id'));
});
    });

      </script> 
 </head> 
 <body> 
  <p id="p1"> no image</p> 
  <p id="p2"> <img src="http://www.java2s.com/style/demo/InternetExplorer.png"> has image </p>  
 </body>
</html>

Related Tutorials