Jump to content

Silly problem: can't add to a string of text (in Mozilla)


V for Vincent

Recommended Posts

Hey there,I've nearly finished my first dynamic website, but there's a small, seemingly stupid problem I can't seem to fix. The site is structured using divs with absolute positioning, but one of these has a variable height. So, in order not to mess up my lay-out (there's a logo underneath the div with variable height), I need to dynamically reposition another div. Here's my code:browser = navigator.appNameif (browser == "Microsoft Internet Explorer"){nieuwsHeight = nieuwscontainer.offsetHeight;}else {docObj = document.getElementById("nieuwscontainer");nieuwsHeight = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");}samalandertop = nieuwsHeight+140document.getElementById("extradiv2").style.top=samalandertopdocument.write(samalandertop)Note that nieuwscontainer is the one with variable height and extradiv2 is the one that needs repositioning. Never mind the funky names. I added the final document.write to track down the problem, and it seems that height is considered a text string in FireFox. Can it be treated as a numerical variable?

Link to comment
Share on other sites

IE is forgiving about dimension while others are not. Your best practice is always append 'px' to your values (or pt or em or whatever your unit is)i.e. document.getElementById("extradiv2").style.top=samalandertop + "px";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...