jQuery gets the tag text content and the html content

  • 2020-05-19 04:14:59
  • OfStack

This article illustrates how jQuery gets the tag text content and html content. Share with you for your reference. The specific analysis is as follows:

jQuery can get the text content of a specified label or html content 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 is helpful for you to design jQuery program.


Related articles: