469,331 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

Creating Floating Div works in IE but not FireFox

This code works in IE (pops up the div) but not in firefox, I cannot see why, any ideas?

Expand|Select|Wrap|Line Numbers
  1. function creatediv(id, html, width, height, left, top) {
  2.  
  3.    if (document.getElementById(id) != null) {
  4.        removediv(id);
  5.    }
  6.  
  7.    var newdiv = document.createElement('div');
  8.    newdiv.setAttribute('id', id);
  9.  
  10.    document.body.appendChild(newdiv);
  11.  
  12.    if (width) {
  13.        document.getElementById(id).style.width = 300;
  14.    }
  15.  
  16.    if (height) {
  17.        document.getElementById(id).style.height = 300;
  18.    }
  19.  
  20.    if ((left || top) || (left && top)) {
  21.        document.getElementById(id).style.position = "absolute";
  22.  
  23.        if (left) {
  24.            document.getElementById(id).style.left = left;
  25.        }
  26.  
  27.        if (top) {
  28.            document.getElementById(id).style.top = top;
  29.        }
  30.    }
  31.  
  32.    document.getElementById(id).style.background = "lightyellow";
  33.    document.getElementById(id).style.border = "4px solid #000";
  34.  
  35.    if (html) {
  36.        document.getElementById(id).innerHTML = html;
  37.    } else {
  38.        document.getElementById(id).innerHTML = "nothing";
  39.    }
  40.  
  41.    document.getElementById(id).style.filter='alpha(opacity=75)'; // IE Semi Transparent Setting
  42.    document.getElementById(id).style.opacity='0.75'; // FireFox Semi transparent Setting
  43.  
  44. function removediv(id) {
  45.   var d = document.getElementById(id);
  46.   document.body.removeChild(d);
  47. }
Feb 21 '08 #1
1 1201
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1.    if (width) {
  2.        document.getElementById(id).style.width = 300;
  3.    }
  4.  
  5.    if (height) {
  6.        document.getElementById(id).style.height = 300;
  7.    }
300 what? Use "px", e.g. 300 + "px".
Feb 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.