Home  >  Article  >  Web Front-end  >  How to use jquery html() method

How to use jquery html() method

coldplay.xixi
coldplay.xixiOriginal
2020-11-16 11:52:523031browse

Usage of jquery html() method: 1. [html()] method sets or returns the content of the selected element; 2. When this method is used to return content, it returns the content of the first matching element. Content; 3. When this method is used to set content, the content of all matching elements is rewritten.

How to use jquery html() method

##Usage of jquery html() method:

Definition and usage

  • html() method sets or returns the content (innerHTML) of the selected element.

  • When this method is used to return content, the content of the first matching element is returned.

  • When this method is used to set content, the content of all matching elements is rewritten.

Tip: If you only need to set or return the text content of the selected element, please use the text() method.

Syntax

Return content:

$(selector).html()

Set content:

$(selector).html(content)

Use function to set content:

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

How to use jquery html() method

##Example

Change the content of all

elements:

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

Related free learning recommendations:
JavaScript

(Video)

The above is the detailed content of How to use jquery html() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn