[ACCEPTED]-What is a jQuery Object?-definitions

Accepted answer
Score: 39

A jQuery object is array-like which means 13 that it contains zero or more indexes (properties 12 which names are positive integers starting 11 with zero). Besides those indexes, a jQuery 10 object contains these properties:

  • length
  • context
  • selector

And also 9 around 140 inherited methods (which are 8 defined on the jQuery.prototype object - you can do console.dir(jQuery.prototype) to 7 get a full list... ).

Note that jQuery objects 6 do not contain (or inherit) the Array methods 5 (slice, substr, ...). If you want to execute 4 those methods on your jQuery object, use 3 call/apply.

For example, if you have 3 TEXTAREA elements 2 on the page and you do this:

var j = $('textarea');

then this j jQuery 1 object will contain these properties:

  • 0 - reference to the first TEXTAREA element
  • 1 - reference to the second TEXTAREA element
  • 2 - reference to the third TEXTAREA element
  • length - which is 3
  • context - reference to the document object
  • selector - which is 'textarea'
  • plus all those inherited methods...
Score: 2

the jQuery object is an object which has 7

  • a length property
  • numeric properties which reference the items from the select (0,1,2,3...)
  • bindings to jQuery functions
  • additional jQuery properties

The length and numeric properties allow 6 the object to respond like an array. You 5 can run it in a for loop or use functions like 4 map or each on it.

I would recommend using your 3 browser's debugger or Firebug and inspect 2 a jQuery object. That will teach you a 1 lot about how it is structured.

More Related questions