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



Description

This returns string that contains the HTML contents of all matched <p> elements.

Syntax

Here is the simple syntax to use this method −

selector.html();

Parameters

None

Example

Following example returns string that contains the combined text contents of all matched <p> elements.

<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() {
            $("#result1").text( $("p").html() );
         });
      </script>		
      <style>
         .red { color:red; }
         .green { color:green; }
      </style>		
   </head>	

   <body>
      <p class="red" id = "pid1"><i>This is first paragraph.</i></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