jQuery HTML Element How to - Set paragraph text value








Question

We would like to know how to set paragraph text value.

Answer


<!--from w  w 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").text("<b>Some</b> new text.");
        });
    </script>
  </head>
  <body>
         <p>asdf</p>
         <p>asdf</p>
         <p>asdf</p>
         <p>asdf</p>
  </body>
</html>

The code above is rendered as follows: