JQuery Html()

jQuery html() method is used to change the entire content of the selected elements.

Below the syntax of jquery html() method

.html();

.html(content);

.html(function (index, currentcontent));

Parameters of jQuery html()
Parameter Description
content Required. Specifies the new content for the selected elements (can contain HTML tags)
function(index,currentcontent)

Optional. Specifies a function that returns the new content for the selected elements

  • index - Returns the index position of the element in the set.
  • currentcontent - Returns the current HTML content of the selected element

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery html()</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $("#button").click(function() {
     $("p").html("Awesome <b>India!</b>")
  });
});
</script>
</head>
<body>
 <button style="margin:0 0 10px 0" class="btn" id="button">Change content of all p elements</button><br />
 <p>This is a paragraph.</p>
 <p>This is another paragraph.</p>
 </body>
</html>