Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery if statement depending on width in px

I'm quite new to jQuery, could someone please tell me if I have expressed the above 'if' statement correctly? I basically want something to run if the width of my variable equals 900px. My variable is var $brewapp = $('#brewapp');

Thanks.

if (($brewapp).width == '900px')
{
//what i want it to do
}
like image 333
Luke Avatar asked Jul 17 '26 06:07

Luke


2 Answers

.width is a function, that returns a number. So your test should look like this:

if ($brewapp.width() === 900)

I suggest the Mozilla Javascript docs if you want to deepen your JS knowledge.

like image 69
Boldewyn Avatar answered Jul 18 '26 19:07

Boldewyn


You need to add only two characters:

if ($brewapp.width() == 900)
{
//what i want it to do
}
like image 39
bjornd Avatar answered Jul 18 '26 19:07

bjornd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!