javascript - Uncaught syntax error: Adding <li> elements to an <ul> -


i keep getting uncaught syntex error know means code has missing closing something. keep failing see missing.

the idea of function extracts links id , text content , add's un-ordered list.

the links have class of 'ingredient_add' , unordered list has id of 'ingredientsadded'.

i can't see i've missed here.

$(document).ready(function() {     $('.ingredient_add').click(function() {         event.preventdefault();         var id = this.id;         var value = this.text();         $('#ingredientsadded').append("<li id='"+id+"'>"+value+"</li>");     }); //end add list }); // end document ready() 

hello problem simple mistake.

var value = $(this).text(); 

here jsfiddle: http://jsfiddle.net/grimbode/pflxf/1/

i updated code. watch out not use same id more once.

$(document).ready(function(){ var counter = 0; $('.ingredient_add').click(function(event){ event.preventdefault(); var id = this.id; var value = $(this).text(); $('#ingredientsadded').append('<li id="'+id+counter+'">'+value+'</li>'); counter+=1; }); //end add list  }); // end document ready() 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -