File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how do I create an Image element in dom to space TDs? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how do I create an Image element in dom to space TDs?" Watch "how do I create an Image element in dom to space TDs?" New topic
Author

how do I create an Image element in dom to space TDs?

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi-
I'm trying to do something like this (so I can space my TDs in a table):

//build footer
var td = document.createElement("td");
var img = document.createTextNode(
"<img src =\"img/shim.gif\" width=\"52"\ height=\"8\"/>");
td.appendChild(img);

q: is there a createImage function for DOM? could not find one. Perhaps there's a nodeType function?
q: is there a better way of doing this?

thanks
Max
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

You can create an IMG element the same way you created your TD element:

var img = document.createElement("IMG");
img.src = "image/shim.gif";

If you use scriptaculous for anything, it can get even easier:

var img = Builder.node("img", {src: "image/shim.gif"});
[ June 19, 2007: Message edited by: Gregg Bolinger ]

GenRocket - A Test Data Generation Platform
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
A better way? Yes do not use an image use CSS for the cell size and get away from the 90's and spacer images.

Eric
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
thanks for the quick replies -
this is a great forum for that -
I will have to through the css tutorial on w3 schools again.
Max
 
 
subject: how do I create an Image element in dom to space TDs?
 
Similar Threads
values undefined in arrays
JavaScript problem with IE
Obtaining data from form elements
dynamically expand and collapse table rows
about checking values between rows with dynamic table created using java script