Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery adds content after a specified element

Shulou Source: shulou.com Published: 2022-05-31 17:02:40 09月10日 Update

This article mainly explains the "jquery how to add content after the specified elements", the content in the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "jquery how to add content after the specified elements" bar!

Two methods: 1, with after (), syntax "$(specified element). After (" new content ")", you can add specified content to the specified element. 2. With insertAfter (), the syntax "$(" content value "). InsertAfter (specified element)", the content can be inserted after the specified element.

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

How does jquery add content after a specified element

To add content after the specified element is to insert the sibling element after the specified element. Jquery provides two methods:

After ()

InsertAfter ()

Both after () and insertAfter () can insert the specified content after the selected element, but their operands are upside down. Let's introduce it in detail.

1. Use after ()

$(A) .after (B) means to insert B after the outside of A.

Example:

$(document) .ready (function () {$("button") .click (function () {$("div"). After ("this is new text content added after div");}) Here are some texts.

This is a p paragraph in the div block.

Add content after div

2. Use insertAfter ()

$(A) .insertAfter (B) means to insert An after the outside of B.

Example:

$(document) .ready (function () {$("button") .click (function () {$("this is a new span element") .insertAfter ("div");}) Here are some texts.

This is a p paragraph in the div block.

Add content after div

Thank you for reading, the above is the content of "jquery how to add content after the specified elements", after the study of this article, I believe you have a deeper understanding of how jquery adds content after the specified elements, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Content elements this is text learning that is methods paragraphs examples grammar available at the same level ideas situations tutorials articles more versions environments computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MariaDB Shulou Information NVidia Shulou Tech Info