javascript - Looping through numbered html tag id's -
i'm having issue not able loop through id's of multiple canvas tags have created edit various pixel data. canvases have id's ranging 0 - n. when id's created, numbers turned strings.
so, if create loop iterates through numbers correspond id's of tags, how make .getelementbyid(); method recognize number value string value? (this might little unclear code should clear things up)
for (var = 0; < 3; i++) { var usegetimagedata = function(i){ var canvas=document.getelementbyid(i); var context=canvas.getcontext("2d"); var imagedata = context.getimagedata(0,0,canvas.width,canvas.height); var data = imagedata.data; } }
the canvas id's are; "0", "1", "2"
try this. weren't calling function (which bad create inside loop anyhow).
var usegetimagedata = function(i){ var canvas=document.getelementbyid(i); var context=canvas.getcontext("2d"); var imagedata = context.getimagedata(0,0,canvas.width,canvas.height); var data = imagedata.data; } (var = 0; < 3; i++) { // usegetimagedata(''+i); // @andrew points out, gets interpreted string. usergetimagedata(i); }
Comments
Post a Comment