Discover javascript document queryselector, include the articles, news, trends, analysis and practical advice about javascript document queryselector on alibabacloud.com
);//foo
If the element whose id attribute is foo is removed, bar is returned when the above method is called. This method is searched based on the selector passed in the parameter. If it is found, it is terminated and this element is returned. Otherwise, null is returned.
Call the document. querySelectorAll () method to return all matching elements contained in the node tree in sequence, such:
var res = document.querySelectorAll("p.warning, p.error");
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
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
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
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 belon
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 i
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
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:
m
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
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
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
]. 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
JavaScript enriched document content, javascript enriched documentEnrich JavaScript content
I. Introduction
Use JavaScript to enrich the document content. The main purpose is to create a list of abbreviations, links to documents,
This method is used to append content to each matching element, which is similar to the case where JavaScript executes the AppendChild method on the specified element and adds them to the document.The parameters are explained as follows:ContentContent to append to the targetfunction (index, HTML)Returns an HTML string that is appended to the inside of each matching element. Accepts two parameters, the index parameter is the indexed value of the object
HTML>Head>Scripttype= "Text/javascript">functionCreatenewdoc () {varNew_doc=Document.open ("text/html","Replace"); vartxt= ""; New_doc.write (TXT); New_doc.close ();}Script>Head>Body>Buttononclick= "Createnewdoc ()">Click to write a new documentButton>Body>HTML>JavaScript document Open () method: Open a new document
=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/5C/wKiom1b9BgyDSD3KAABxoI2Jouo849.png "title=" Web.png "alt=" Wkiom1b9bgydsd3kaabxoi2jouo849.png "/>Top and bottom elements-As with the node tree, the element nodes on the element tree also have parent-child relationships, which can be obtained using the following properties:650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/58/wKioL1b9Bx2hJcVLAABm5ndfpl4870.png "title=" Web.png "alt=" Wkiol1b9bx2hjcvlaabm5ndfpl4870.png "/>elements that a
Getting started with JavaScript Document Object Model, getting started with javascriptPreface:
The Document Object Model (DOM) is a standard programming interface recommended by W3C for processing Extensible slogans. It is a platform-and language-independent application interface (API) that can dynamically access programs and scripts and update their content, str
Full-stack JavaScript path (22) IE proprietary extension-document mode, javascript path
Ie8 introduces a new concept, "document mode". The document mode of the page determines what functions can be used. That is to say, the "document
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.