admin管理员组文章数量:1193808
What is the difference between javascript window and jquery $(window)?
I tried in the Chrome console and I get this:
So, I would conclude is "just" a window object wrapped in a jquery object in a way that then I can use jquery's functions on it (like height(), width(), etc...)
I did try googling, and stackoverlowing :) OFC, but to no luck.
What is the difference between javascript window and jquery $(window)?
I tried in the Chrome console and I get this:
So, I would conclude is "just" a window object wrapped in a jquery object in a way that then I can use jquery's functions on it (like height(), width(), etc...)
I did try googling, and stackoverlowing :) OFC, but to no luck.
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jun 5, 2013 at 11:52 NikolaNikola 15k21 gold badges106 silver badges170 bronze badges 5 |4 Answers
Reset to default 15When you write $(window)
, you should know that that piece of code is going to run on the JS engine. Have you ever wondered why jQuery objects all have parentheses around them? It is because $
is a function object. Basically you're calling the $
function, and passing the native global, or window
object to it as an argument.
If you browse through the jQuery source code, you'll see that it'll pass that object on to many internal functions and in the end, it'll return a jQuery wrapper object.
So yes, your assumptions are pretty much correct.
You are ture
window, which is a jQuery wrapper containing the global window object. The intent here was to create a locally-scoped window variable that would give me immediate access to jQuery methods like width(), height(), scrollLeft(), and scrollTop().
window is a global object and have no relation to any 3rd party library. however $(window) returns a jQuery object. You are right that its nothing but a wrapper but it comes with all possible jQuery goodies. We can use it just like normal jQuery object we can access its childs, can associate data wtih it etc etc.
The window
object represents the window itself. You can find more explanation here. From what you describe above, it seems that you are looking to access the document
properties instead of window
properties. You can access the properties length, height, etc. as follows:
- document.height (pure javascript) or $(document).height() (jQuery)
- document.width (pure javascript) or $(document).width() (jQuery)
For more document
properties, see here.
本文标签: What is the difference between (window) and window in jqueryjavascriptStack Overflow
版权声明:本文标题:What is the difference between $(window) and window in jqueryjavascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738459651a2087956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
window.$(window) === $(window)
– Néstor Waldyd Commented Jul 15, 2022 at 5:06