Home>Article>Web Front-end> How to replace html content with jquery

How to replace html content with jquery

青灯夜游
青灯夜游 Original
2021-05-19 17:03:41 5800browse

Replacement method: 1. replaceWith() replaces the selected element with new content, the syntax is "$(selector).replaceWith(content)"; 3. replaceAll() uses the specified HTML content or element Replace selected elements, syntax "$(content).replaceAll(selector)".

How to replace html content with jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

1. replaceWith()

Replace the selected content with the content in the brackets.

$("#div").replaceWith("
div2
");

Usage as above, replace the element with ID div with the DIV element with ID div2.

2. replaceAll()

Replace the selected content with the selector in brackets.

$("
替换后的内容
").replaceAll("p");

Usage as above, replace all p tags with the selected DIV tag.

Recommended related video tutorials:jQuery Tutorial(Video)

The above is the detailed content of How to replace html content with jquery. 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