Home > Web Front-end > Front-end Q&A > How to get content without tags in jquery

How to get content without tags in jquery

青灯夜游
Release: 2022-03-23 18:02:03
Original
2238 people have browsed it

In jquery, you can use the text() method to obtain the content without tags in the specified element. This method will return the text content of the matching element with the HTML tag removed. The syntax is "$(selector).text( )".

How to get content without tags in jquery

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

In jquery, you can use the text() method to obtain the content without tags in the specified element.

text() method sets or returns the text content of the selected element.

  • #When this method is used to return content, the text content of all matching elements is returned (HTML tags will be removed).

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

Syntax for returning text content with HTML tags removed:

$(selector).text()
Copy after login

Example:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					alert($("p").text());
				});
			});
		</script>
	</head>
	<body>

		<button>返回所有p元素的文本内容</button>
		<p>这是<b>一个</b>段落。</p>

	</body>
</html>
Copy after login

How to get content without tags in jquery

If the content of the HTML tag is not deleted (the content obtained by the html() method), it will return:

How to get content without tags in jquery

##[Recommended learning:

jQuery video tutorialwebfrontend

The above is the detailed content of How to get content without tags in 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