Home > Web Front-end > JS Tutorial > Relevant introduction to operating nodes in jQuery_jquery

Relevant introduction to operating nodes in jQuery_jquery

WBOY
Release: 2016-05-16 17:36:40
Original
940 people have browsed it

Dynamicly create Dom nodes

jQuery uses $(html string) to dynamically create Dom nodes and returns a jQuery object. You can call append and other methods to add the created node to the Dom.

For example:

var link = $("Baidu");

$("div:first").append(link);

How to add node elements:

The Append method is used to append an element (the last child node) at the end of the element

Prepend adds an element (the first child node) at the beginning of the element

After: Add elements after elements (add sibling nodes)

Before: Add elements before elements (add sibling nodes)

Child element.appendTo(parent element): Append a child element

at the end of the element

Child element.prependTo(parent element): Append a child element

at the beginning of the element

A.insertBefore(B) Insert A in front of B, which is equivalent to B.before(A);

X.insertAfter(B) Insert X after Y, equivalent to Y.after(X);

Delete node:

Empty(): Clear all child nodes under this element

Equivalent to: while(ele.firstChild){ele.removeChild(ele.firstChild);}

Remove(selectot); commit suicide; delete the current element, and the return value is the deleted element. You can say that the node is deleted and placed under other nodes, which has a moving effect, for example:

var lis = $("#ulSite li").remove();

$("#ulSite2").append(lis);


Clone() clones the node, supports copying the node, and does not copy the node

Clone(true): Clone node with event


Node replacement:

$("br").replaceWith("


");

$("br").replaceAll("


");

Wrap Node

The Wrap() method is used to wrap all elements with specified tags one by one

$("b").wrap("");Display all bold characters in red

wrapInner(); wraps

inside
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template