Home > Web Front-end > JS Tutorial > jQuery DOM Insert Node Operation Guide_jquery

jQuery DOM Insert Node Operation Guide_jquery

WBOY
Release: 2016-05-16 16:11:17
Original
1100 people have browsed it

prependTo()after()Insert content after each matching element
Method Description Example
append() Append content inside of each matching element

HTML code:

I want to say:

jQuery code:

$("p").append("Hello");

Result:

I want to say:Hello

appendTo()

Append all matching elements to the specified element

. In fact, using this method is to reverse the convention

The operation of $(A).append(B) in

is to append A to B.

HTML code:

I want to say:

jQuery code:

$("Hello").appendTo("p")

Result:

I want to say:Hello

prepend() Prepend content inside of each matching element HTML code:

I want to say:

jQuery code:

$("p").prepend("Hello")

Result:

HelloI want to say:

Prepend all matching elements to the specified element

. In fact, using this method is upside down

Regular $(A).prepend(B) operation.

HTML code:

I want to say:

jQuery code:

$("Hello").prependTo("p")

Result:

HelloI want to say:

HTML code:

I want to say:

jQuery code:

$("p").after("Hello")

Result:

I want to say:

Hello

insertAfter()

Insert all matching elements into the specified element

After the element, actually, use this method

Inverts the regular $(A).after(B) operation

HTML code:

I want to say:

jQuery code:

$("Hello").insertAfter("p")

Result:

I want to say:

Hello

before() Insert content before each matched element

HTML code:

I want to say:

jQuery code:

$("p").before("Hello")

Result:

Hello

I want to say:

insertBefore()

Insert all matching elements into the index

The front of a certain element. Actually,

Using this method is to reverse the convention

’s $(A).before(B) operation.

HTML code:

I want to say:

jQuery code:

$("Hello").insertBefore("p")

Result:

Hello

I want to say:

The above is the entire content of this article, I hope you all like it.

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