jQuery Page Widget How to - Append Text node created by document








Question

We would like to know how to append Text node created by document.

Answer


<!--from   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").html("<b>bold</b>");
               $("p b").append(document.createTextNode("added")).css("color", "red");
        });
    </script>
  </head>
  <body>
         <p>asdf</p>
  </body>
</html>

The code above is rendered as follows: