Add a list elements within an unordered list element using jQuery.
HTML Code :
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Add li in an existing ul.</title> </head> <body> <div id="header"> <ul> <li><a href="https://www.w3resource.com/python/python-tutorial.php">Python</a></li> <li><a href="https://www.w3resource.com/php/php-home.php">PHP</a></li> </ul> </div> <input type="button" value="Click to add new li element" onclick="new_element()" /> </body> </html>
JavaScript Code :
function new_element(){ $("#header ul").append('<li>Java</li>'); }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code :
JavaScript Code :