Can an element's width be dynamically set using the following code:
<img id="backgroundImg" src="images/background.png" alt="" width="javascript:getScreenSize()['width']+px" height="1100px"/>
In this code, getScreenSize() is a JavaScript function.
function getScreenSize()
{
var res = {"width": 630, "height": 460};
if (document.body)
{
if (document.body.offsetWidth) res["width"] = document.body.offsetWidth;
if (document.body.offsetHeight) res["height"] = document.body.offsetHeight;
}
if (window.innerWidth) res["width"] = window.innerWidth;
if (window.innerHeight) res["height"] = window.innerHeight;
alert( res['width'] );
return res;
}
Alternatively, should the img's width be adjusted within a JavaScript function?
function changeImgWidth( img )
{
img.offsetRight = getScreenWidth()['width'] + "px";
}