Add text before of an element's original text - Javascript jQuery

Javascript examples for jQuery:Text

Description

Add text before of an element's original text

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-2.0.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from w  w w.j  a va  2  s .  c o  m*/
$("#button").click(function() {
    $( ".text" ).prepend( document.createTextNode( " Hello" ) );
});
    });

      </script> 
 </head> 
 <body> 
  <button id="button">Button</button> 
  <div class="text">
    Some random text 
  </div>  
 </body>
</html>

Related Tutorials