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; 

full js fiddle code

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("")); 

updated demo

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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -