What is the use of jquery replaceall method

青灯夜游
Release: 2022-04-22 12:00:35
Original
1569 people have browsed it

jquery replaceAll() method is used to replace the selected elements with new HTML elements, the syntax is "$(content).replaceAll(selector)"; the parameter "selector" specifies the selected element, and "content" specifies Contains replacement content for HTML tags.

What is the use of jquery replaceall method

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

jquery replaceall() method

replaceAll() method replaces the selected elements with new HTML elements. Syntax format:

$(content).replaceAll(selector)
Copy after login
##ParameterDescriptionRequired. Specifies the content to be inserted (must contain HTML tags). Required. Specifies which element will be replaced.
content
selector
can be simplified to:

$(A).replaceAll(B), which means replacing the B element with the A element.

Example 1: Replace the strong element with an a element

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(function() {
				$("button").click(function() {
					 $(&#39;<a href="https://www.php.cn/" target="_blank">PHP中文网</a>&#39;).replaceAll("strong");
				})
			})
		</script>
	</head>
	<body>
		<strong>jQuery教程</strong><br/>
		<br><button>隐藏textarea</button>
	</body>
</html>
Copy after login

What is the use of jquery replaceall method

Example 2: Replace the last p element Description for the span element

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(function() {
				$("button").click(function() {
					$("<span><b>Hello world!</b></span>").replaceAll("p:last");
				})
			})
		</script>
	</head>
	<body>
		<p>这是一个段落。</p>
		<p>这是另一个段落。</p>
		<br><br><button>隐藏textarea</button>
	</body>
</html>
Copy after login

What is the use of jquery replaceall method

: The

:last selector selects the last element. This selector only uses For selecting a single element

The most common usage: used with other selectors to select the last element in a specified combination (such as the example above).

[Recommended learning:

jQuery video tutorial, web front-end video]

The above is the detailed content of What is the use of jquery replaceall 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