This is the html code:
Code: Select all
<ul id="lists">
<li>List Item 0</li>
</ul>
<button id="btn1">Append List</button>
<button id="btn2">Remove List</button>
Code: Select all
List Item 1
List Item 2
List Item 3
Code: Select all
<ul id="lists">
<li>List Item 0</li>
</ul>
<button id="btn1">Append List</button>
<button id="btn2">Remove List</button>
Code: Select all
List Item 1
List Item 2
List Item 3
Code: Select all
<ul id="lists">
<li>List Item 0</li>
</ul>
<button id="btn1">Append List</button>
<button id="btn2">Remove List</button>
<script>
var it = 1;
// append LI in #lists
$('#btn1').click(function(){
$('#lists').append('<li>List Item '+ it +'</li>');
it++;
});
// Remove last LI from #lists
$('#btn2').click(function(){
$('#lists li:last').remove();
it--;
});
</script>