开发者

What are the "document" and "location" called in $(document) and $(location)?

The most basic thing in JQuery seems to be to write $(document).ready(...). If I understand the "document" there represents the DOM of the HTML page. Does it have a name in JQuery terms? Is it a "selector"? Is the list of methods I can cal开发者_如何学运维l on available somewhere in the JQuery documentation?

The same goes for the $(location), what is that called? object?

What other such things (for no better name for now) are available in JQuery? Where are they documented?


jQuery can "wrap" any DOM object. You can also do it with $(window) and with $(myObj)where myObj is your own variable set like var myObj = document.getElementById("div1");.

When you give jQuery object/element then it's not using any selectors, but you can have:

$("document").ready(function() {

And this is using selector and works same way.


The document is not selector, it rather "global" DOM object. jQuery could wrap any DOM element providing nice interface, so jQuery could be called Adapter pattern.

This code,

$(document).ready(function () {});

simply said, take document object, subscribe to ready event and call my custom callback that document is on ready state. You basically could do the same with pure JavaScipt but it would be more complicated (more code in particular).

Location is a part of window (window.location) URL of current document, I dont see any reasons to wrap it with jQuery like $(location)

EDIT

I found this good example of using $(location), so the stuff I said above it not quite true.

Get current URL in JavaScript?


"document" and "location" are just global variables set for js context by a web-browser.

Global variables are kept in a "root" object. You can reference that root object by "window" in browser's javascript. For example in google chrome you can press Ctrl+Shift+J, click "scripts" tab, pause script execution and add a "watch expression" for "window" to see what's inside. There's a lot and all these objects and properties are just the environment set by web-browser to enable your scripts to interact with a web-page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜