How to Add <li> in an Existing <ul> using jQuery
append()
You can simply use the jQuery append() method to add <li> elements in an existing <ul> element.
<li>
<ul>
The following example will add a <li> element at the end of an <ul> on click of the button.
<!DOCTYPE html> <html lang="en"> <head> <title>jQuery Add LI to an Existing UL</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#menu").append('<li><a href="#">New list item</a></li>'); }); }); </script> </head> <body> <ul id="menu"> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Services</a></li> </ul> <button type="button">Add New LI Element</button> </body> </html>
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.
Use the jQuery
append()MethodYou can simply use the jQuery
append()method to add<li>elements in an existing<ul>element.The following example will add a
need an explanation for this answer? contact us directly to get an explanation for this answer<li>element at the end of an<ul>on click of the button.