Home > Web Front-end > JS Tutorial > How to add a line of information at the end with jquery

How to add a line of information at the end with jquery

WBOY
Release: 2021-11-23 17:18:57
Original
2317 people have browsed it

Jquery method to add a line of information at the end: 1. Use the "$(element)" statement to match the element object you want to add information to; 2. Use the append() method to add a line of information at the end of the element, syntax It is "element object.append("Information to be added");".

How to add a line of information at the end with jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

How to add a line of information at the end in jquery

In jquery, you can use the append() method to add a line of information at the end, the append() method Inserts the specified content at the end (still inside) of the selected element.

The syntax of this method is:

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

where content represents the content to be added in the last line.

Let’s take a look at the following example:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("p").append(" <p>这是在最后添加的一行信息</p>");
  });
});
</script>
</head>
<body>
<p>这是初始的一行信息</p>
<button>在每个 p 元素的结尾添加内容</button>
</body>
</html>
Copy after login

Output result:

How to add a line of information at the end with jquery

After clicking the button:

How to add a line of information at the end with jquery

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to add a line of information at the end with jquery. 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