javascript - Iterating jquery objects -
i attempting iterate , output values of choices property using jquery each(). code seems output array index , not string values. why this? here jsfiddle
var allquestions = [ { question: "who prime minister of united kingdom?", choices: ["david cameron", "gordon brown", "winston churchill", "tony blair"], correctanswer:0 }]; $(info[0].choices).each(function(value){ $('#answers').append($('<li>').text(value)); });
you have confused
$(selector).each()
with
$.each(array, callback)
http://api.jquery.com/jquery.each/
you want use second form iterating on arrays.
Comments
Post a Comment