Asked
Updated
Viewed
20.6k times

I have the following CSS style applied to an HTML element:

<div id="diamonds" style="position:absolute; left:0px; top:0px; width:130px; height:255px; z-index:1; visibility: hidden;">

I have a function that changes it with JavaScript:

b.left=X_pos;
b.top=Y_pos;
alert('X_pos= '+X_pos+' left= '+b.left+' Y_pos= '+Y_pos+' top= '+b.top);

It changes the left and top CSS attributes to a new value. In Internet Explorer it sees the new value and changes the left and top to the new number, however in Firefox while it sees the new number (it knows what X_pos is) but it does not change the style to the new number. So while this works for changing the position in Internet Explorer, how do I change the style in Firefox?

add a comment
1

2 Answers

  • Votes
  • Oldest
  • Latest
Answered
Updated

Try:

b.left = 255 + "px";
b.top = 255 + "px";
  • 0
    b is the actual css style declaration object. If I do this: b.left=255; b.top=255; alert(b.top);, then IE says : 255px and FF says : 0px. — halfasleeps
  • 0
    Ah, wasn't very clear from the code you posted. With firefox, you may have to specify the units concatenated onto the value, that is, making sure px is appended to the end. — katana
  • 0
    THANK YOU SO MUCH you saved me!...i been trying to many things to figure it out and all i needed to do was add px to the end....whoo — halfasleeps
add a comment
1
Answered
Updated

a good way to make it would be to make more than one stylesheet with different names then use cookies and pull the cookies in with the rel="" in order for it to catch the correct stylesheet, doign it this way will make it compatable on all browsers, many browsers fail to work with some JavaScript things

  • 0
    I don't think that's anything to do with halfasleep's problem. He's changing the content of his page dynamically using JavaScript - not something you can do with CSS files. — katana
  • 0
    Correct because I am setting a drop-down menu to be placed right under the button that calls it. It used to be a static x and y but I made it so I can move the button around and the drop-down menu follows it. — halfasleeps
  • 0
    I jumped to conclusions, user-custom styles are a common thing people ask for. — Bozebo
add a comment
0