jQuery prependTo() Method

Last Updated:

jQuery prependTo() Method

The jQuery prependTo() method inserts specified content at the beginning of the selected elements.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery prependTo() Method</h1> <p>My name is Jade </p> <button>Click me more than once</button> <script> $(document).ready(function(){ $("button").click(function(){ $("<strong>I like programming and </strong>").prependTo("p"); }); }); </script> </body> </html>

Syntax

$(htmlString).prependTo(selector);

Parameter Values

ValueTypeExplanation
htmlString Required Specifies a html string to be prepended.
selector Required Specifies the selector to which the html string should be prepended.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
prependTo()YesYesYesYesYesYesYesYesYesYesYesYesYes

Share this Page

Meet the Author