Example:
<div class="test"><img src="test.jpg" style="display:none;" /></div>
How to change that with javascript, I know in css its:
.test img {display:block;}
but in javascript I only know this:
document.getElementById("test").style.display="block";
thats obviously the whole div tag , not the img.
If you’re using an ID
"test", you can do this.This uses
getElementsByTagNamewhich returns a collection of the images found. The[0]grabs the image at index0(the first image), and then applies the style.If you have a class
"test", you can do this, but it won’t work in IE7 and below:For the widest browser compatibility, you can do this: