Home >Web Front-end >JS Tutorial >Example of usage of prependTo() method in jQuery_jquery

Example of usage of prependTo() method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:21:361199browse

The example in this article describes the usage of prependTo() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method inserts the matching element before the specified element.
The prependTo() method has the same function as the prepend() method, but there are differences in syntax, although it looks the same in form.

Grammar structure:

Copy code The code is as follows:
$(selector).prependTo(content)

Parameter list:
参数 描述
selector 要被插入的匹配元素。
content 要被插入匹配元素的元素。

Example code:

Copy code The code is as follows:






prependTo() function-Script Home





I am the content of p


I am div




Note: After running the editor, press F5 to refresh the web page to view the demo.
The above code can move the p element to the front inside the div after clicking the button.

I hope this article will be helpful to everyone’s jQuery programming.

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