1

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 call 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?

szabgab
  • 6,202
  • 11
  • 50
  • 64

3 Answers3

1

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.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • 1
    of course... this never worked because "document" is a selector, rather it worked because .ready() is (or was when this answer was written) a method on *all* jquery objects. at one point this was deprecated... but i'm unsure if it was ever removed. – Kevin B Apr 03 '23 at 22:14
0

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?

Community
  • 1
  • 1
Alexander Beletsky
  • 19,453
  • 9
  • 63
  • 86
  • Your answer was infinitely better before the "EDIT". There is never a reason to wrap something like `location`, or a standard js object, in a jquery collection. – Kevin B Apr 03 '23 at 22:12
0

"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.

scaryzet
  • 923
  • 4
  • 9