Javascript: edit an images height in a for loop -
i'm trying edit images height repeating in loop in javascript can't figure out need add in.
here variables if it's important:
var i; var start = 1; var seg = document.getelementbyid("selsegs").value; var parent = document.getelementbyid("divinch"), //parent appendchild imagepath = 'inchwormsegment.gif', //variable image img; //adding img element
here loop:
for(i = start; i<=seg; i++) { img = new image(); //creating new image object img.src = imagepath; // element src = imagepath img.style.height = "215px"; // sets height of in loop // img.style.height = (img.style.height * .9) + "px"; - nothing parent.appendchild(img); //appendchild adds child (img) object }
i've tried adding in math can't figure out supposed go
let me know if fiddle accomplishes trying do: http://jsfiddle.net/ayny5/. few things remember:
- you can edit image "height" attribute directly, no need go through style (you don't need add px!)
- don't use new image() - use document.createelement('img'). that's w3c supported standard.
if i'm off let me know - otherwise, on right track!
js code in fiddle:
var parent = document.getelementbyid("imgholder") (i=0;i<3;i++) { var img = document.createelement('img'); img.src = "http://bit.ly/1975wka" img.height = "200" parent.appendchild(img) }
Comments
Post a Comment