Home > Article > Web Front-end > How to add a line of information at the end with jquery
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");".
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:
After clicking the button:
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!