admin管理员组文章数量:1357276
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
}
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
}
Share
Improve this question
asked May 26, 2011 at 9:12
LukeLuke
2053 silver badges16 bronze badges
3 Answers
Reset to default 3.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.
You need to add only two characters:
if ($brewapp.width() == 900)
{
//what i want it to do
}
I guess your code should be:
if ($brewapp.width() == 900)
{
//what i want it to do
}
First width is a function, so use () and it returns an integer, so no need to append 'px'.
This is the jQuery way. Using the jQuery width() gives better results than using el.style.width (or what you intended to use).
本文标签: javascriptjQuery if statement depending on width in pxStack Overflow
版权声明:本文标题:javascript - jQuery if statement depending on width in px - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744039804a2580452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论