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( )".
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()
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>
If the content of the HTML tag is not deleted (the content obtained by the html() method), it will return:
##[Recommended learning:jQuery video tutorial 、webfrontend】
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!