Home > Web Front-end > JS Tutorial > jQuery's method of obtaining tag text content and html content_jquery

jQuery's method of obtaining tag text content and html content_jquery

WBOY
Release: 2016-05-16 16:07:23
Original
1437 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

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