Javascript Tutorial: querySelector () method,
Module dom {[Supplemental, NoInterfaceObject]Interface NodeSelector {Element querySelector (in DOMString selectors );NodeList querySelectorAll (in DOMString selectors );};Document implements NodeSelector;DocumentFragment implements NodeSelector;Element implements NodeSelector;};
From the interface definition, we can s
The javascript advanced selector querySelector and querySelectorAll are fully parsed. The selector
The querySelector and querySelectorAll methods are defined in the W3C Selectors API specification. Their role is to easily locate specified elements in the document according to the CSS selector specification.
Almost all mainstream browsers currently support them. I
The following small series will bring you a comprehensive analysis of the javascript advanced selector querySelector and querySelectorAll. I think it is quite good. Now I will share it with you and give you a reference. Let's take a look at the querySelector and querySelectorAll methods defined in the W3C Selectors API specification. Their role is to easily locat
In fact, there are many descriptions about querySelector and querySelectorAll. This is mainly to make a record. At the beginning, many people will use the jquery selector to compare with the two APIs (I am also). It is okay to compare the similarities and differences, however, some people misunderstand the implementation of these two APIs in the browser, especially when calling this api on dom element.
The following is my jsFiddle example. I will desc
= items.length i Logger.append (items[i].innerhtml);
}
Logger.flush ();
})();
The misconception is that the realization of the $ (' inner '). Queryselectorall (' #main h4.inside ') is understood, and many people begin to think of it directly from the children of Div[id= ' inner ' (Me too), this # Main is a bit of an eyesore. It actually looks up from the entire document according to the selector string, and then returns the child nodes belonging to div[id= ' inner '. Many people will w
elements are updated in real time. document.getElementById returns the real time result, after adding a child element to it, gets the number of all the child elements again, has been updated by the original 2 to 3 (here is not considered some browsers such as Chrome will also resolve the white space as a child node).
Element.queryselector and Element.queryselectorall and jquery (Element). Find (Selector) selector difference:
queryselectorall Find all nodes in the document that
In fact, there are many descriptions about querySelector and querySelectorAll. Here we mainly make a record. At the beginning, many people will use the jquery selector to compare the two APIs (I am also ), the similarities and differences are similar, but some people may misunderstand the implementation of these two APIs in the browser, especially when calling this api on dom element.
The following is my jsFiddle example. I will describe it here:
T
Module DOM {[Supplemental, Nointerfaceobject]Interface Nodeselector {Element Queryselector (in domstring selectors);NodeList Queryselectorall (in domstring selectors);};Document implements Nodeselector;DocumentFragment implements Nodeselector;Element implements Nodeselector;};From the interface definition you can see that document, DocumentFragment, element all implement the Nodeselector interface. That is, the three types of elements are owned by two
In fact, there are many descriptions about queryselector and queryselectorall.
This is mainly a record.
At the beginning, many people will use the jquery selector to compare with the two APIs (I am also). The similarities and differences are actually okay, however, some people misunderstand the implementation of these two APIs in the browser, especially when calling this API on Dom element.
The following is my jsfiddle example. I will describe it h
The two methods should be returned according to W3C specifications. Let's take a look at the official explanation first, and then choose to use them according to W3C specifications:
QuerySelector:Return the first matching Element node within the node's subtrees. if there is no such node, the method must return null. (return the first child tree of the specified element node that matches the selector set. If no child tree matches the selector, return null)
QuerySelectorAll:
Return a NodeList
The Queryselector and Queryselectorall methods are defined in the selectors API specification. Their role is to conveniently locate the specified element in the document according to the CSS selector specification.They are now supported by almost all major browsers. Includes IE8, Firefox, Chrome, Safari, Opera.Queryselector and Queryselectorall define the following interfaces in the specification:
module DOM {[Supplemental, Nointerfaceobject]
Article Introduction: The Queryselector () method accepts a CSS query and returns the first descendant element of the matching pattern, or null if no matching element is returned.
The Queryselector () method accepts a CSS query and returns the first descendant element of the matching pattern, or null if no matching element is returned. Take a look at the following example:
Get the BODY element
]. innerHTML );}
Logger. flush ();})();
The misunderstanding lies in $ ('inner '). querySelectorAll ('# main h4.inside') Implementation understanding, many people initially think that it is directly from the div [id = 'inner '] Child Search (I am also ), this # main is a bit confusing. In fact, it searches for the entire document based on the selector string and returns the child node that belongs to the div [id = 'inner. Many people may wonder why it is not implemented simply by finding Child N
In traditional JavaScript development, DOM searching is often the first headache for developers. There are not many DOM selection methods provided by native JavaScript, but only through tag, name, id, and other methods to search, which is obviously far from enough. If you want to make a more precise choice, you have to use a seemingly cumbersome regular expression, or use a library. In fact, all browser ven
In traditional JavaScript development, finding DOM is often the first headache for developers, and native JavaScript offers little dom options, limited to finding by tag, name, ID, and so on, which is clearly far from enough if you want to A more precise choice of rows is to have to use a regular expression that looks very cumbersome, or to use a library. In fact, all browser vendors now offer support for b
Introduction to the native powerful DOM selector querySelector, domqueryselector
In traditional JavaScript development, DOM searching is often the first headache for developers. There are not many DOM selection methods provided by native JavaScript, but only through tag, name, id, and other methods to search, which is obviously far from enough. If you want to mak
Today, we will introduce the HTML5 knowledge. We will introduce you to the topic of the new selector. The selector introduced today is querySelector (). I will share with you the comparison between jQuery and JavaScript. I hope this will help you learn HTML5.
The querySelector () method receives a CSS selector and returns the first element that matches the patter
Native powerful Dom Selector queryselectorIn traditional JavaScript development, finding the DOM is often the first headache that developers encounter, and native JavaScript does not provide much of a DOM selection, only limited to finding it through tags, name, id, and so on, which is obviously far from enough if you want to enter A more precise choice of rows would have to use a regular expression that lo
HTML5 introduced the new Document.queryselector and Document.queryselectorall two methods to the Web API to make it easier to pick elements from the DOM and function like a jquery selector. This makes it much easier to write native JavaScript code.1. UsageTwo methods use the same syntax, which is to receive a string parameter, which needs to be a valid CSS selection syntax.element = Document.queryselector (' selectors '= Document.queryselectorall (' s
Brief introductionHTML5 introduced the new Document.queryselector and Document.queryselectorall two methods to the Web API to make it easier to pick elements from the DOM and function like a jquery selector. This makes it much easier to write native JavaScript code.UsageTwo methods use the same syntax, which is to receive a string parameter, which needs to be a valid CSS selection syntax.element = Document.queryselector (' selectors '); elementlist =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.