Using elements that are added to an array with (document.getElementById(‘ID’))

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'));

Leave a Comment