Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add child elements in jquery

Shulou Source: shulou.com Published: 2022-06-01 03:56:08 09月20日 Update

In this article, the editor introduces in detail "how to add sub-elements in jquery". The content is detailed, the steps are clear, and the details are handled properly. I hope this "how to add sub-elements in jquery" article can help you solve your doubts.

The method of adding child elements in jquery: 1, append (), you can add child elements at the end of the selected element, syntax "$(parent element). Append (child element)"; 2, appendTo (), you can append the child element to the end of the specified element, syntax "$(child element). AppendTo (parent element)".

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

There are two ways to add child elements (add child elements at the end) in jquery:

Append ()

AppendTo ()

JQuery append () method

In jQuery, we can use the append () method to insert content into the "end" inside the selected element.

Syntax:

$(A) .append (B)

Indicates that B is inserted at the end of the inside of A.

Example:

$(function () {$("# btn") .click (function () {var $li = "banana"; $("ul") .append ($li) }) Apple, pear, orange

JQuery appendTo () method

In jQuery, the functions of the appendTo () and append () methods are similar, inserting content into the "end" inside the selected element, but their operands are reversed.

Syntax:

$(A) .appendto (B)

Indicates that An is inserted at the end of the inside of B.

Example:

$(function () {$("# btn") .click (function () {var $li = "durian"; $($li) .appendto ("ul") }) Apple, pear, orange, banana

After reading this, the article "how to add sub-elements in jquery" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Tags: Elements endings methods content grammar articles two pears oranges examples apples bananas propriety similarity functions available in ideas tutorials new knowledge more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Apple Redmi MariaDB