Home > Web Front-end > JS Tutorial > body text

关于jQuery object and DOM element_jquery

WBOY
Release: 2016-05-16 17:37:01
Original
994 people have browsed it

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!