Description :
prepend()
method is used to Inserts content at the start of the selected elements.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").prepend(" prepended Text."); }); }); </script> </head> <body> <p>This is a Heading.</p> <button>prepend text</button> </body> </html>
Description :
In this example,prepend()
method is used to Inserts multiple content at the start of the selected elements. We can take an infinite number of new elements as parameters.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $(".btn1").click(function(){ $("div").prepend("Appwrk."); }); }); </script> </head> <body> <div>jquery</div> <div>javascript</div> <div>ASP.net</div> <button class="btn1">prepend text</button> </body> </html>
Description :
In this example, prepend() method is used to Inserts List items at the start of the selected elements. Here we have used HTML <ol> tags to display the selected list. We can take an infinite number of new elements as parameters.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("ol").prepend("<li>Prepended Items</li>"); }); }); </script> </head> <body> <ol> <li>List1</li> <li>List2</li> <li>List3</li> </ol> <button>Prepend List Items</button> </body> </html>