javascript - Jquery returns a list using id selector -
i'm having trouble jquery , selectors using following code:
<div id="test"></div> console.log($('#test'));
this returns list [<div id="test"></div>]
instead of single element.
this results on having write $('#test')[0]
every operations instead of $('#test')
. idea on why?
regards
jquery not return htmlelement, returns jquery object.
a jquery object contains collection of document object model (dom) elements have been created html string or selected document. since jquery methods use css selectors match elements document, set of elements in jquery object called set of "matched elements" or "selected elements"
the jquery object behaves array; has length property , elements in object can accessed numeric indices [0] [length-1]. note jquery object not javascript array object, not have methods of true array object such join(). http://api.jquery.com/types/#jquery
this example of composite design pattern
the composite pattern describes group of objects can treated in same way single instance of object can. implementing pattern allows treat both individual objects , compositions in uniform manner. in jquery, when we're accessing or performing actions on single dom element or group of dom elements, can treat both in uniform manner. http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#designpatternsjquery
Comments
Post a Comment