jQuery HTML Element How to - Set HTML for paragraph








Question

We would like to know how to set HTML for paragraph.

Answer


<!--  ww w.j a v  a  2s . 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("<span class='red'>Hello <b>Again</b></span>");
        });
    </script>
  </head>
  <body>
         <p>asdf</p>
  </body>
</html>

The code above is rendered as follows: