Results 1 to 3 of 3

Thread: document.[name].style.... problem!!

  1. #1
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation document.[name].style.... problem!!

    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
    Last edited by Francisco Dias; 11-29-2007 at 09:05 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The preferred method these days is by id:

    Code:
    document.getElementById('some_id').style.left='10px';
    Or, if used in a function where the id is supplied as x:

    Code:
    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:

    Code:
    function movemenu(x, n){
    document.getElementById(x).style.left=n+'px';
    }
    The getElementById method is case sensitive.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thankkkk UUU!!

    You rule man!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •