SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member benasp's Avatar
    Join Date
    Dec 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    z-index in style

    Hi
    I want to change z-index of div id="test0" from 10 to 9 by JavaScrtipt.

    Whate is wrong in this code: ?
    Code:
    var obraz = 0;
    var tab = new Array();
    tab[0] = 'test0';
    tab[1] = 'test1';
    ...
    document.getElementById(tab[obraz]).style.z-index = 9;
    ...
    <div id="test0">
    <img src="a34.jpg">
    </div>
    ...
    I have javaScript error:
    Code:
    invalide  assignment left-hand side
    http://ben.cproject.pl/php/foto/text1.php
    document.getElementById(tab[obraz]).style.z-index = 9;

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm confused as to why you are using getElementById(tab[obraz]) rather than: getElementById(tab[0]) which equals the value of the div you want to set the z-index for.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementById(tab[obraz]).style.z-index = 9;
    Style properties have to be strings (though IE is sometimes sloppy about this), and the hyphen is a minus sign!
    The error is what happens when you subtracted 'index' from z (z-index=) as part of the left hand assignment.

    Use document.getElementById(tab[obraz]).style.zIndex = '9'


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
  •