Home >Web Front-end >JS Tutorial >How to use jQuery's insertAfter() method

How to use jQuery's insertAfter() method

青灯夜游
青灯夜游Original
2019-02-14 15:41:212957browse

jQuery's insertAfter() method is used to insert some HTML content after a specified element. Its usage syntax is "$(content).insertAfter(target)", where content represents the HTML content that needs to be inserted. .

How to use jQuery's insertAfter() method

The operating environment of this article: Windows 7 system, jquery version 3.2.1, Dell G3 computer.

insertAfter() is a built-in method of jQuery, used to insert some HTML content after a specified element. The following article will introduce to you the usage of insertAfter(), I hope it will be helpful to you.

jQuery's insertAfter() method

The insertAfter() method inserts HTML content every time the specified element appears.

Basic sentence pattern:

$(content).insertAfter(target)

content: Indicates the HTML content that needs to be inserted.

target: Indicates the specified target that needs to be found before inserting content.

Note: insertAfter() method does not return any value.

[Video tutorial recommendation: jQuery tutorial]

Usage example of insertAfter() method

Let’s look at specific examples below:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".demo").click(function() {
// insertBefore 
$("<div style=&#39;color: red;&#39;>在PHP中文网中学习!</div>").insertAfter("p");
});
});
</script>
</head>
<body>
<div class="box">
<p>学习jQuery</p>
<p>学习php</p>
<div class="demo">单击此处</div>
</div>
</body>
</html>

Rendering:

How to use jQuerys insertAfter() method

##The above is the entire content of this article, I hope it can be helpful to everyone’s learning help. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to use jQuery's insertAfter() method. 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