Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2021-11-23 17:18:572269browse

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)

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>

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!

Statement:
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