Home > Web Front-end > JS Tutorial > body text

How to use jquery html() method

coldplay.xixi
Release: 2020-11-16 11:52:52
Original
3103 people have browsed it

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()
Copy after login

Set content:

$(selector).html(content)
Copy after login

Use function to set content:

$(selector).html(function(index,currentcontent))
Copy after login

How to use jquery html() method

##Example

Change the content of all

elements:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template