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

How to replace html content with jquery

青灯夜游
Release: 2023-01-06 11:14:22
Original
5895 people have browsed it

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("<div id="div2">div2</div>");
Copy after login

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.

$("<div>替换后的内容</div>").replaceAll("p");
Copy after login

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!

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