JQuery prepend_ add text in Div

 

In this example creates a <div> element and uses >code>prependTo() method to append the element at the start of parent element.

 
 
 
<!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <style> .parent { height: 100px; width: 300px; background: rgb(0, 126, 128); margin: 0 auto; } .newElement { height: 40px; width: 100px; margin: 0 auto; color: rgb(141, 21, 21) } </style> </head> <body style = "text-align:center;"> <h1 style = "color:rgb(119, 0, 128);" >welcome to Appwrk Solution</h1> <div class= "parent"></div> <br><br> <button onclick="insert()"> insert </button> <script> function insert() { $('<div class = "newElement">Hello! we are From' + ' Appwrk Team</div>').prependTo($('.parent')); } </script> </body> </html>
Output