I've got an object generator. It works properly.
'use strict';
function Div(isim) {
this.loc = document.getElementById(isim);
var style = window.getComputedStyle(this.loc);
this.width = style.getPropertyValue('width');
this.height = style.getPropertyValue('height');
this.left = style.getPropertyValue('left');
this.top = style.getPropertyValue('top');
}
But later I am updating the properties of the element
var d = new Div("d");
d.loc.style.left = getRandomInt(0, window.innerWidth - 50) + "px";
d.loc.style.top = getRandomInt(0, window.innerHeight - 50) + "px";
console.log(d.left); //gives auto
console.log(d.width); //gives the right value
and console.log(d.left)
is wrong. I have already found a way to fix it but it is a bit dirty, I think:
var d = new Div("d");
d.loc.style.left = getRandomInt(0, window.innerWidth - 50) + "px";
d.loc.style.top = getRandomInt(0, window.innerHeight - 50) + "px";
d = new Div("d");
console.log(d.left); //gives the right value
console.log(d.width); //gives the right value
Is there an another way(one line I prefer)? And Unfortunately, I am not good at English and if there are mistakes in question, title, please edit them.