Is it possible to redefine a style at runtime?
For example, assume I have a definition
img {
height: 100%;
}
When a page loads, I'd like to redefine the images to be 75% of the available body height.
I created a routine that I execute in the onload() event to change each image to a calculated height - I'm wondering whether there's a better, or more generic, way to do this.Changing the rules directly is possible, but full of incompatibilities (<!-- m --><a class="postlink" href="http://www.quirksmode.org/dom/w3c_css.html">http://www.quirksmode.org/dom/w3c_css.html</a><!-- m -->).
Better is creating an array of the element then changing each property value:
onload=function() {
var aImg=document.getElementsByTagName('img');
for(var i=0; i<aImg.length; i++) {
aImg.style.width=someValue;
}
}Thanks for the info. There's a whole whack of things I'd never heard of in there.
I had set up a loop to do the adjustment, as you suggested. I'll probably leave it at that - why break a working program? I'm sure the next change I make will introduce its own set of problems...
For example, assume I have a definition
img {
height: 100%;
}
When a page loads, I'd like to redefine the images to be 75% of the available body height.
I created a routine that I execute in the onload() event to change each image to a calculated height - I'm wondering whether there's a better, or more generic, way to do this.Changing the rules directly is possible, but full of incompatibilities (<!-- m --><a class="postlink" href="http://www.quirksmode.org/dom/w3c_css.html">http://www.quirksmode.org/dom/w3c_css.html</a><!-- m -->).
Better is creating an array of the element then changing each property value:
onload=function() {
var aImg=document.getElementsByTagName('img');
for(var i=0; i<aImg.length; i++) {
aImg.style.width=someValue;
}
}Thanks for the info. There's a whole whack of things I'd never heard of in there.
I had set up a loop to do the adjustment, as you suggested. I'll probably leave it at that - why break a working program? I'm sure the next change I make will introduce its own set of problems...