jQuery html()

jQuery html() method can either be used to set content ( where it overwrites the content of all the matched elements) or can be used to return content ( where it returns the content of the first matched element).

jQuery html() sets or returns the content of selected elements.


When it is used to return content.


When it is used to set content.


Content: Content is a compulsory parameter, used to specify the new content for the selected elements.

When it is used to set content by calling function.

$(selector).html(function (index, currentcontent))

Function: It is an optional parameter that returns the new content on calling.

Index: It is passed as an argument inside the function to show the index position of the element.

Current content: This is another argument passed inside the function to show the current HTML content of the selected element.


<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
$("p").html("Hello! I am back.</b>");
<button>Click me</button>
<p>Bye Bye!</p>
Please follow and like us:
Content Protection by DMCA.com