jQuery prependTo: Main Tips
- The jQuery
.prependTo()
adds HTML content to the beginning of selected elements. - The
prependTo
jQuery is different from .prepend() due to syntax rules: the new content precedes the function. Keep that in mind when using the chaining functionality.
Usage of .prependTo() Explained
The .prependTo()
method makes jQuery insert HTML content at the beginning of the selected target. The following example adds a blockquote to the <p>
element:
Example
$("button").click(() => {
$("<blockquote>Hello World</blockquote>").prependTo("p");
});
Follow these syntax rules for the .prependTo()
jQuery method:
$(content).prependTo(target);
content
specifies the HTML content to insert to the selected elements.target
defines a target to which HTML elements will receive new content. You may either insert a selector here, or define the exact target (an HTML string, a jQuery object, a single element or an array).
Latest Udacity Coupon Found:
Verified STAFF PICK
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!
Expiration date: 30/01/2021
3176 People Used
Only 97 Left