PDA

View Full Version : document.[name].style.... problem!!



Francisco Dias
11-29-2007, 03:52 PM
i'm developing a menu and I'm having some problems.
I wanted to do a general code move items on a menu.

example:

before after
_______ ________
|_______ |________
|_______ |________
|_______ |________
|_______ |________

it is activated by mouseover, and I wanted to create a function that covered all buttons at once.

function movemenu(x) //x is the name of the img//

document.[x value].style.left =....

but nothing happens!!

Resume: I wanted to call name (or id) as a variable

jscheuer1
11-30-2007, 05:13 AM
The preferred method these days is by id:


document.getElementById('some_id').style.left='10px';

Or, if used in a function where the id is supplied as x:


function movemenu(x){
document.getElementById(x).style.left='10px';
}

Also, units (such as px) must be specified in most browsers for top, left, height, and width (as well as for a number of other style properties). If you are passing the value as a number held in a variable, the units must still be applied:


function movemenu(x, n){
document.getElementById(x).style.left=n+'px';
}

The getElementById method is case sensitive.

Francisco Dias
12-01-2007, 01:40 AM
You rule man!! :D