- This jQuery method is used to insert the given content at the starting of the selected HTML element means this method insert the specified content as the child element by the user before the beginning of the matched element.
prepend() and prependTo() both jQuery methods are used for same work but the only difference between these methods is in their syntax.
- content: This represents the contents which to be insert at the starting of the selected elements. It is mandatory and must contain HTML tags. If the content is already exists on the webpage then it will be moved at the starting of the selected element.
- selector: selector represents a jQuery selector that is used to select the HTML element.
In this example we insert a new <span> at the beginning of every <p> tag.
<title> jQuery Example </title>
border:1px solid green;
$text="<span class='sp'>Welcome freinds!! </span>";
<h2> jQuery prependTo() method Example </h2>
<p> This is the paragraph 1 </p>
<p> This is the paragraph 2 </p>
<p> This is the paragraph 3 </p>
<p> This is the paragraph 4 </p>
<button> Click me! </button>
When you click the button,
Waiting for your comments