JQuery if width dependent operator in px

I am new to jQuery, can someone please tell me if I formulated the above if statement correctly? I basically want something to start if my variable width is 900px. My variablevar $brewapp = $('#brewapp');

Thank.

if (($brewapp).width == '900px')
{
//what i want it to do
}
+3
source share
3 answers

.widthis a function that returns a number. Therefore, your test should look like this:

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

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

+3
source

You need to add only two characters:

if ($brewapp.width() == 900)
{
//what i want it to do
}
+3
source

, :

if ($brewapp.width() == 900)
{
//what i want it to do
}

- , use() , "px".

jQuery. jQuery width() , el.style.width( , ).

+1

All Articles