开发者

Differences between window.location.hash and $(window).location.hash

开发者 https://www.devze.com 2023-02-19 07:21 出处:网络
Are there any differenc开发者_如何学Pythones between window.location.hash and $(window).location.hash?There are differences - jQuery will parse and preform a bunch of unnecessary operations on the obj

Are there any differenc开发者_如何学Pythones between window.location.hash and $(window).location.hash?


There are differences - jQuery will parse and preform a bunch of unnecessary operations on the object, so just doing window.location.hash is better.


Wrapping things like this or window inside a call to $ is only useful when you want to use a jQuery method on the resulting object, since a call to $ will return the object wrapped inside a jQuery object. So, in this case, just use window.location.hash


Well, one works, the other doesn't.

Doing $(window) will wrap the window object inside a jQuery object, and the jQuery object doesn't have a location property, so you will get undefined back. As you can't get the property hash (or any property) from undefined, the code ends with the error message "$(window).location is undefined".

0

精彩评论

暂无评论...
验证码 换一张
取 消