jwdbjbebefin jwdbjbebefin - 1 year ago 63
jQuery Question

if statement command becomes invalid if page size over 1000

I have an if statement on my website which does commands when the page is under a certain size. there is one small problem. if the page size is over 1000 it automatically says the if statement is not true and goes to the else. my attempts are bellow

if($("body").css("width") < 700 + "px")

I have tried a plain < and I have also done <= I'm kinda new to jquery, all help would be kindly appreciated.

Answer Source

You are comparing strings. Strip off the trailing "px" from the left value (How to delete "px" from 245px) and compare numbers.

if(parseInt($("body").css("width") , 10) < 700)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download