I have a for loop, and I want that in my line, the left property of style, depends on my variable:
var pos = (i*100+100)px;
document.getElementsByName("ok")[i].style = 'position:absolute; left:pos';
Something like that.
I have a for loop, and I want that in my line, the left property of style, depends on my variable:
var pos = (i*100+100)px;
document.getElementsByName("ok")[i].style = 'position:absolute; left:pos';
Something like that.
You can something like this
var pos = (i*100+100);
const elem = document.getElementsByName("ok")[i];
elem.style.position = 'absolute';
elem.style.left = pos + 'px';
I think you are looking for something like
var DOM_elements = document.getElementsByName("ok");
for(var i=0; i < DOM_tags.length; i++) {
var element = DOM_elements[i];
var pos = (i*100+100);
element.setAttribute('style','position:absolute; left:' + pos.toString());
}
This is risky though. You are in effect overwriting all other attributes of style (is that what you want?). Also worth noting - element.style
is an object (not a string), so perhaps you would like element.style.position = 'absolute';
or something like that.