setAttribute("style", foo) err, Multiple CSS attr's

A

awebguynow

OK, I'm on the bandwagon, to mimic Google Suggest
At this point I'm just trying to place my div in the right x, y spot.

newdiv.setAttribute("style", "position:absolute;left:"+x+";top:"+y);
mybody.appendChild(newdiv);

Using Firefox's DOM inspector, I only saw "position:absolute"
Does a multi-attribute CSS specification, have to be set another way ?
 
R

Randy Webb

awebguynow said the following on 5/16/2006 10:58 PM:
OK, I'm on the bandwagon, to mimic Google Suggest
At this point I'm just trying to place my div in the right x, y spot.

newdiv.setAttribute("style", "position:absolute;left:"+x+";top:"+y);

setAttribute is buggy, access the properties directly:

newdiv.style.position = 'absolute';
newdiv.style.left = x + 'px';
newdiv.style.top = y + 'px';

Or:

with (newdiv.style){
position = 'absolute';
left = x + 'px';
top = y + 'px'
}

top and left require a unit.
mybody.appendChild(newdiv);

Using Firefox's DOM inspector, I only saw "position:absolute"
Does a multi-attribute CSS specification, have to be set another way ?

Probably so. Hence the name setAttribute and not setAttributes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top