hi every body I’m trying to open an image in a new window ,using javascript, by clicking on a button, then set a class to the image, using this code:
OpenWindow=window.open("", "newwin","height=100,width=1000");
OpenWindow.document.write("<img id='img1' src='webfonts.jpg'>");
OpenWindow.document.getElementById("img1").className = "larger";
OpenWindow.document.close();
and this is the internal style I have included in my code in a style tag:
.larger{ width:10px; }
and in the body tag
1:I have include my image source by an img tag
2:make a button tag with an onclick=larger() attribute
but unfortunately I have a problem with last sentence, the class is not assigned at all to the image.
I have tried to use classname also instead of setttribute but it generates the same result.
any ideas?
thx
First, the code you wrote is wrong. There’s an apostrophe too much behind
img.Second, you didn’t assign an ID to your
imgelement, so you can’t access it withdocument.getElementById.Use something like