Home > Article > Web Front-end > jQuery's method of obtaining tag text content and html content_jquery
The example in this article describes how jQuery obtains tag text content and html content. Share it with everyone for your reference. The specific analysis is as follows:
jQuery can obtain the text content or html content of the specified tag through the text and html methods
<!DOCTYPE html> <html> <head> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#btn1").click(function(){ alert("Text: " + $("#test").text()); }); $("#btn2").click(function(){ alert("HTML: " + $("#test").html()); }); }); </script> </head> <body> <p id="test">This is some <b>bold</b> text in a paragraph.</p> <button id="btn1">Show Text</button> <button id="btn2">Show HTML</button> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.