vForums Support > Programming & Coding :: Code Requests & Support :: > Bring element to top (z-index)

Bring element to top (z-index) - Posted By Aiken (ionfortuna) on 11th Jan 10 at 7:27pm
Code:
 
  1. <script>
  2. var TopZ = 101;
  3. function SetZ(WinID){
  4. TopZ++
  5. get(WinID,'id').style.z-index = TopZ;
  6. }
  7. </script>
 


I want it so every time you "open" certain elements they are brought to the top and if you have one above another if you click the lower one it will bring it to the top

Re: Bring element to top (z-index) - Posted By Michael (wrighty) on 11th Jan 10 at 7:35pm
Code:
 
  1. <script>
  2. var TopZ = 101;
  3. function SetZ(WinID){
  4. TopZ++
  5. get(WinID,'id').style.zIndex = TopZ;
  6. }
  7. </script>
  8.  
  9. <div id = 'x' onclick = "SetZ('x');" style = 'position: relative; top: 15px; left: 10px; padding: 50px; border: 1px solid #000000; background: #800000; color: #FFFFFF; width: 200px;'>
  10. RAWR!
  11. </div>
  12. <div id = 'y' onclick = "SetZ('y');" style = 'position: relative; top: -15px; left: 20px; padding: 50px; border: 1px solid #000000; background: #800000; color: #FFFFFF; width: 200px;'>
  13. RAWR2!
  14. </div>
  15. <div id = 'z' onclick = "SetZ('z');" style = 'position: relative; top: -40px; left: 30px; padding: 50px; border: 1px solid #000000; background: #800000; color: #FFFFFF; width: 200px;'>
  16. RAWR3!
  17. </div>
  18. <div id = '1' onclick = "SetZ('1');" style = 'position: relative; top: -45px; left: 40px; padding: 50px; border: 1px solid #000000; background: #800000; color: #FFFFFF; width: 200px;'>
  19. RAWR4!
  20. </div>
 


The JS to change the Z-Index is
x.style.zIndex = 'number';
{Smile}

Re: Bring element to top (z-index) - Posted By Aiken (ionfortuna) on 11th Jan 10 at 7:41pm
Works exactly the way I want it to, thanks

Re: Bring element to top (z-index) - Posted By Michael (wrighty) on 11th Jan 10 at 7:58pm
You're welcome! {Smile}