Saturday, 15 March 2014

javascript - Get html value from object within an array -



javascript - Get html value from object within an array -

i have exemplary javascript code snippet. i'm trying accomplish here getting html, , id attribute value object within array

var swatches = $(".swatchcolor"); (var = 0; < swatches.length; i++) { var value = parseint(swatches[i].html()); if (!isnan(value)) { alert(swatches[i].attr("id")); } };

but reason uncaught typeerror: undefined not function error when swatches[i].html() executed. why happen?

the jquery class selector not provide array of node elements iterate through.

from this answer, need next iterate through of nodes:

$(".swatchcolor").each(function(i, obj) { var value = parseint($(obj).html()); //etc... });

javascript jquery dom

No comments:

Post a Comment