HTML jQuery Document Actions - html () method

 

jQuery HTML - html () method

Examples

Set contents of all p elements:

$(".btn1").click(function(){
  $("p").html("Hello <b>world</b>!");
});

Try it yourself

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()

Try it yourself

Setting element content

When using this method to set a value, it will cover all the matching content elements.

grammar

$(selector).html(content)

 

 
 

Try it yourself

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))

Try it yourself

 

 

parameter description
function(index,oldcontent)

A new provision to return the contents of the selected element function.

  • index - optional. Receiving a selection of an index position.

oldcontent - optional. Receiving a selection of the current contents.

Here we try img tag na?

 

Guess you like

Origin www.cnblogs.com/-zhong/p/10972823.html