Which object returns jquery exactly?

I have been working on my own JavaScript library for a long time, and everything works fine. But I was wondering about the jQuery return object.

Suppose you have multiple divs in your DOM and you select them using $("div") jquery actually returns the selected nodes (like an object / array?) In the console log and you can hover them over them to see where they are in the documents.

My object actually returns the whole object, so if you call kj("div") (where kj is my object name), it appears in the console log:

  > kj > elements: Array[10] > length : 10 > more stuff 

My question is: how can I get it to return something like jQuery?

Thanks in advance.

+7
source share
3 answers

I think that you are looking for that in jQuery an array of elements is the main object, methods and other information are connected to this array as properties.

 function $$(tagname){ var x = document.getElementsByTagName( tagname ); x.moreStuff = true; return x; } var d = $$('div'); 

because typeof Array === 'object' you can arbitrarily attach methods and properties to an array.

+3
source

JQuery connects its own references to an object, which, in turn, refers to things in dom. These links are a little more complicated than just โ€œhtml contentโ€, as there are related events. JQuery also has very efficient "selectors" that iterate over dom and create these links.

I have to say I agree with Scrum Meister. Today, jQuery is a generally accepted standard even for the development of Microsoft (WOOHOO!). Why not use it?

+3
source

Open the console on this page and do console.log($('#custom-header')) and you will get the result. I think jquery will return an object with the following methods and property that we use for them, like hide() and show() . I think it is better to use jquery to create another library.

 >>> console.log($('#custom-header')) [div#custom-header] 0 div#custom-header context Document what-is-the-jquery-returned-object-exactly jquery "1.4.4" length 1 selector "#custom-header" init function() TextAreaResizer function() _toggle function() add function() addClass function() addSpinner function() addSpinnerAfter function() after function() ajaxComplete function() ajaxError function() ajaxSend function() ajaxStart function() ajaxStop function() ....... ....... ....... 
0
source

All Articles