View Full Version : positioning images with javascript.

01-28-2006, 06:45 PM
Hi All,
I have no specific reference to give you. Rather new to javascript, fully conversant on CSS HTML etc If i borrow a javascript from someone else and wish to change the position of images how can i do it. What commands are available except for the <center> and using <br /> all the time. I have searched the entire internet and havent found a decent answer. Appreciate any ideas?


01-28-2006, 07:07 PM
You can set document.images['imageNameOrID'].style.offsetLeft and .offsetTop as you like.

01-29-2006, 07:37 PM
Thanks, But where exactly to insert this text. In the script, body or style? Does anyone know of anymore image commands for position = absolute etc for Javascript. Or using CSS commands on a pre-written javascript. Any input would be much appreciated.


01-29-2006, 07:49 PM
But where exactly to insert this text. In the script, body or style?A script, of course. The image must be absolutely positioned. Don't use my code directly; it's only informational. CSS attributes can be set in Javascript with element.style.attributeName, where element is an element object. The only thing you need to watch out for is that hyphens are replaced by camel notation; for example, background-color becomes backgroundColor.

01-29-2006, 07:56 PM
Could you point me in the direction of some examples to follow? Thanks in advance

01-29-2006, 08:51 PM
Move image with name/id of "irge" to 60x20 from the top of the page:
<script type="text/javascript">
var e = document.images['irge'].style;
e.position = "absolute";
e.offsetLeft = "60px";
e.offsetTop = "20px";

01-29-2006, 08:57 PM
Thanks so much!!