Home > Web Front-end > Front-end Q&A > Can jquery be called to obtain the content of the html page?

Can jquery be called to obtain the content of the html page?

WBOY
Release: 2022-06-09 10:29:21
Original
1356 people have browsed it

jquery can be called to get the content of the html page, just use the html() method; this method is used to set or return the content of the html element. When used to return the content of the element, the returned result is the first The content of a matching element, the syntax is "$(selector).html()".

Can jquery be called to obtain the content of the html page?

The operating environment of this tutorial: windows10 system, jquery3.4.1 version, Dell G3 computer.

jquery calls the html page content

html() method to set or return the content of the selected element (innerHTML).

When this method is used to return content, the content of the first matching element is returned.

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

The syntax is:

Return content:

$(selector).html()
Copy after login

Set content:

$(selector).html(content)
Copy after login

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("p").html());
});
});
</script>
</head>
<body>
<button>获取这个P元素的内容</button>
<p>这是一个 <b>段落</b>。</p>
</body>
</html>
Copy after login

Output result:

Can jquery be called to obtain the content of the html page?

After clicking the button:

Can jquery be called to obtain the content of the html page?

##Video tutorial recommendation:

jQuery video tutorial

The above is the detailed content of Can jquery be called to obtain the content of the html page?. 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