jQuery HTML - html () method
Examples
Set contents of all p elements:
$(".btn1").click(function(){
$("p").html("Hello <b>world</b>!")
;
});
Definition and Usage
HTML () method returns or sets the contents of the selected element (inner HTML).
If the method parameter is not set, the contents of the currently selected element is returned.
Returns the element content
When using this method returns a value, it returns the contents of the first matching element.
grammar
$(selector).html()
Setting element content
When using this method to set a value, it will cover all the matching content elements.
grammar
$(selector).html(content)
parameter | description |
---|---|
content | Optional. Provisions of the new contents of the selected element. The parameters may include HTML tags. |
Use function to set the element content
Use function to set all the content matched elements.
grammar
$(selector).html(function(index,oldcontent))
parameter | description |
---|---|
function(index,oldcontent) | A new provision to return the contents of the selected element function.
oldcontent - optional. Receiving a selection of the current contents. |
Here we try img tag na?