Why does this code not work?
var all_obj_element= new Array();
all_obj_element[0]= document.getElementById('Img3');
alert(all_obj_element[0].style.width);
The alert shows an empty box!
Because you haven't set the width. Here is how you get the computed style value of an element:
var computedStyle = function (el,style) {
var cs;
if (typeof el.currentStyle != 'undefined'){
cs = el.currentStyle;
}
else {
cs = document.defaultView.getComputedStyle(el,null);
}
return cs[style];
}
Now let's get the value:
var element = document.getElementById('Img3');
alert(computedStyle(element,'width'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With