I have a list of elements, two user input fields, and two buttons. User enters a value in the 1st input field and clicks on the button. The entered value should be appended to the existing list and should also reflect in the space provided below the input fields. All the added values should form a comma separated string.
Ex: car, bike, bus
How to concatenate a variable which is a user input value to form a comma separated line using jquery?
Html:
<ol id="list">...</ol>
<input class="Add">
<button id="btn1"> Add </button>
Added item : <div class="Additem"></div>
Jquery:
$("#btn1").click(function(){
var additem = $(".Add").val();
$("#list").append("<li>" + additem + "</li>");
$(".Additem").append("<div>" + additem + "</div>");
Line 4 in the above code appends the variable but in a different line.
Above operation shows a method of appending a user input value to list. What is the method to delete a user input value which is a part of list?