jQuery HTML Element How to - Create text node and add after a paragraph








Question

We would like to know how to create text node and add after a paragraph.

Answer


 <!--   w ww  .  j  a  v a 2 s.  c  o m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
              $("p").after( document.createTextNode("Hello") );
        });
    </script>
  </head>
  <body>
     <p> a</p><b>b</b>
  </body>
</html>

The code above is rendered as follows: