javascript - jquery removing items from the array doesn't work -
i able find answer changed bit , tried make work without success.
i remove item when user press x button:
part of js code:
animals = temp; (var = 0; < animals.length; i++) { newoutput += '<p>' + animals[i] + '<input type="number" class="animals-input pull-right text-right" value="0" />' + '<a href="#" onclick="deleteitem(' + animals[i] + ')" class="pull-right delete-item">x</a></p>'; }; $('.animals-input').innerhtml = newoutput;
any ideas?
thanks.
you can this:
(var = 0; < animals.length; i++) { newoutput.push('<p>' + animals[i] + '<input type="number" class="animals-input pull-right text-right" value="0" />' + '<a href="#" onclick="deleteitem(\'' + + '\')" class="pull-right delete-item">x</a></p>'); }; $('#list').html(newoutput.join(""));
you need change this
onclick="deleteitem(' + animals[i] + ')"
to
onclick="deleteitem(\'' + + '\')"
as in deleteitem()
function passing array index not array value. also, need put quotes while passing parameter function, otherwise errors.
Comments
Post a Comment