Get span contents ignoring H2 - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:remove

Description

Get span contents ignoring H2

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.7.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from  ww  w  . j  a  v  a2 s.  com*/

var copy = $(document).find('span').clone();
$(copy).find('h2').remove();
console.log($(copy).text());

    });

      </script> 
 </head> 
 <body> 
  <span> <h2>H2 H2</h2> test test test</span>  
 </body>
</html>

Related Tutorials