1

When I came back to work this morning I could reload and see the weird behavior, after restarting the server it was gone. I can not recreate it. So the question is "solved", feel free to delete it, I am not sure if I am allowed to do so.

I try to return the window and document height on a resize event. Based on their values, I try to do the following using an if/else statement (Very basic but it doesn't seem to work, so I logged the data):

Inside the if statement I logged "TRUE [number one] >= [number two]" inside the else statement I logged "FALSE [number one] >= [number two]". This was triggered on a window resize event. Then I resized the window horizontally, so the height values do not change. With two identical numbers I assumed that it logs always the TRUE part but output is:

[...]
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
[...]

The type of the value is always "number", it is always an integer, no float. I also "Tested" in IE9 and FF35.

Can someone explain what is going on? How can I avoid this behaviour?

Thank you!

EDIT: My original question was edited. It is o.k. to improve my English (I am still learning the language), but now the question is a different one as you see in the first answer. I did NOT ask how to get the height of the elements (so "I try to return ..." is not my intention), my question is about the behaviour of the if statement with two given equal values. I just tried to explain how I got there. – There is a difference between eliminating spelling errors and interpreting the text to another meaning.

2
  • 11
    Can you include the code that ran this check? I suspect there's some minor detail in the implementation that will shed light on the issue.
    – ssube
    Jan 26, 2015 at 20:49
  • I wrote the code in the office, now I am at home and am unable to look at it. I will copy&paste it tomorrow. It is like a = $(window).height(), b = $(document).height(), then: if (a >= b) log TRUE else log FALSE. It is all very simple and basic and with curly braces and semicolons. I thought it does not matter, because the output is as I wrote above, and the main question is: why is (548 >= 548) false? :)
    – user4496236
    Jan 26, 2015 at 21:01

1 Answer 1

0

With no doctype tag Chrome, Firefox, and Safari report the same value for both calls.

<!DOCTYPE HTML>

Adding a strict doctype causes the values to work as advertised.

This is most likely the same in several browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.