Connecting Tech Pros Worldwide Forums | Help | Site Map

DOM image load problem

Newbie
 
Join Date: Aug 2007
Posts: 10
#1: Aug 29 '08
My Javascript looks like this:
Expand|Select|Wrap|Line Numbers
  1. var myObject = document.createElement("div");
  2. myObject.setAttribute("class", "myclass");
  3. myObject.appendChild(document.createTextNode("The content to go in the myObject DIV"));
My class looks like this:
Expand|Select|Wrap|Line Numbers
  1. .myclass
  2. {
  3.     margin-left:20px;
  4.     margin-right:20px;
  5.     width:200px;
  6.     height:200px;
  7.     background:url(objectbg.png) repeat-y left top;
  8. }
My problem is that the background image doesn't load. I have checked the Page Info in Firefox and objectbg.png does not exist in the media list.
What can I do to fix this?

gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#2: Aug 30 '08

re: DOM image load problem


try the following instead of using setAttribute:

Expand|Select|Wrap|Line Numbers
  1. myObject.className = 'myclass';
kind regards
Reply


Similar JavaScript / Ajax / DHTML bytes