Tuesday, July 31, 2012

html – Changing body tag style through JavaScript



i\’m trying to write a script to change the width of the page considering user\’s client width.

it\’s something like this :



function adjustWidth() {
width = 0;
if (window.innerHeight) {
width = window.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) {
width = document.documentElement.clientWidth;
} else if (document.body) {
width = document.body.clientWidth;
}
if (width < 1152) {
document.getElementsByTagName(\"body\").style.width=\"950px\";
}
if (width >= 1152) {
document.getElementsByTagName(\"body\").style.width=\"1075px\";
}
}
window.onresize = function() {
adjustWidth();
};
window.onload = function() {
adjustWidth();
};


with this script i get an error from Firebug:



document.getElementsByTagName(\"body\").style is undefined


now my question is, how can i access the style of body ? because in css sheet it\’s selector and width property are defined.






Rating: 1 out of 5 based on 4 ratings



The post html – Changing body tag style through JavaScript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-changing-body-tag-style-through-javascript.html

No comments:

Post a Comment