Break span into different elements using jQuery - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:replaceWith

Description

Break span into different elements using jQuery

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 ava  2 s  . c o  m*/
var orig = $('#foo').text().split(' '),str='';
$(orig).each(function (idx, elem) {
    str += '<span id="foo' + (idx + 1) + '">' + elem + '</span>';
});
$('#foo').replaceWith(str);
    });

      </script> 
 </head> 
 <body> 
  <span id="foo">0.00 (0.00%)</span>  
 </body>
</html>

Related Tutorials