Home >Web Front-end >JS Tutorial >关于jQuery object and DOM element_jquery

关于jQuery object and DOM element_jquery

WBOY
WBOYOriginal
2016-05-16 17:37:011044browse

Origin:

Copy code The code is as follows:

                                                                                                                       

                                                                                                                         

                                                                                                                   

& lt;/div & gt;

Want to get text in span elements, find $ ("#test1 span") [0]. ("#test1 span")[0]).text() was converted to jQuery and then retrieved, but the two $ together always felt weird, so the next best thing was to use the value$("#test1 span") [0].textContent or $("#test1 span")[0].innerHTML jQuery object and DOM elementjQuery object is an array-like object that can contain one or more DOM element(s). The operations of jQuery functions are based on jQuery object rather than DOM object. eg. jQuery object “Object[span, span, span]” contains one or more DOM elements “”. The way to access the DOM element in jQuery object:



Copy the code The code is as follows: $(" selector")[0] // Accesses the first DOM element in this jQuery object
$("selector").get(0) // Equivalent to the code above
$("selector").get( ) // Retrieve a true array of DOM elements matched by this selector


or non-jQuery way:


Copy code The code is as follows:document.getElementsByTagName("div") // Return HTMLcollection


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn