How to Add <li> in an Existing <ul> with jQuery
In this tutorial, we are going to see how to add <li> in an existing <ul> with jQuery. You can simply use jQuery’s append() method to add a list item to an existing unordered list.
The following example will add the <li> element to the end of the <ul> list by clicking the button.
How to Add <li> in an Existing <ul> with jQuery
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#langages").append('<li><a href="#">New language</a></li>');
});
});
</script>
</head>
<body>
<ul id="langages">
<li><a href="#">JavaScript</a></li>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
</ul>
<button type="button">Add new language</button>
</body>
</html>
| Result |
|---|




