jQuery Method How to - Use append() to append HTML to selected tag








Question

We would like to know how to use append() to append HTML to selected tag.

Answer


<!--from w  w  w.  j ava 2  s . c  om-->
<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").append("<strong>Hello</strong>");
        });
    </script>
  </head>
  <body>
         <p>asdf</p>
         <p>asdf</p>
         <p>asdf</p>
         <p>asdf</p>
  </body>
</html>

The code above is rendered as follows: