Rustam Rustam - 5 months ago 40
HTML Question

how to remove li element

I have folllowing funtion:

function addPhone()
var value= $('#Membership_c_tel').val();

url: '/cabinet/membership/addPhone',
type: 'POST',
cache: false,
data: {'val':value},
beforeSend: function() {
success: function (r) {
var val=document.getElementById("Membership_c_tel").value;
$("#newly_create_tel").append("<li class="+val+">"+document.getElementById("Membership_c_tel").value+"<a href='#' class=''>x</a></li>");

error: function (e) {


The function is responsible for adding
<ul id="newly_create_tel ">
when user submit data using inputbox with id=Membership_c_tel. At the same time
<a href="#">x</a>
is also added with
. The problem is i do not know how to delete specific
element when x pressed. How can i achieve to it? Help me.

$('#newly_create_tel li a').click(function(event){



You need to use event delegation since it's dynamically generated and get li using parent() or closest() method.

$('#newly_create_tel').on('click', 'li a', function(event){