Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic