jQuery Examples - $("p").html("Hello World")



Description

This would set the HTML content of all matching <p> to Hello World.

Syntax

Here is the simple syntax to use this method −

selector.html(htmlcontent);

Parameters

Here is the description of all the parameters used by this method −

  • htmlcontent This is the value to be set to the matched element.

Example

Following example would set the HTML content of all matching <p> to Hello World.

Live Demo
<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>   
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("p").html("<i>Hello World</i>");
         });
      </script>		
      <style>
         .red { color:red; }
         .green { color:green; }
      </style>		
   </head>	

   <body>
      <p class="red" id = "pid1">This is first paragraph.</p>
      <p class="selected" id = "pid2">This is second paragraph.</p>
      <div id = "result1"></div>      
   </body>	
</html>

This will produce following result −

jqueryexamples_attributes.htm
Advertisements