search
HomeWeb Front-endJS TutorialExt.get() and Ext.query() are used in combination to achieve the most flexible way of fetching elements_jquery

I have omitted the parameters for get() and query() written earlier. Let’s take a look at the function prototype in the document first:
Ext.get( Mixed el ) : Element
Parameters:
el : Mixed
The id of the node, a DOM Node or an existing Element.
Returns:
Element
The Element object
Ext.query( String path, [Node root] ) : Array
Parameters:
path : String
The selector/xpath query
root : Node
(optional) The start of the query (defaults to document).
Returns:
Array
The query function actually returns an array of DOM Node, and the parameter el of Ext.get can be a DOM Node, haha, do you understand? That is to say, to achieve the most flexible retrieval method, you should use query to obtain the DOM Node and then hand it to get to turn it into an Element. That is:
var x=Ext.query(QueryStr);
//Why don’t I write it as an inline function? Because x here can only be one element, and x in the above sentence is an Array, you can convert and process it yourself
var y=Ext.get(x);
Then the format of QueryStr needs to be introduced next (In fact, it is very similar to the format of the selector in jQuery). As for what you can do after obtaining the Element, you can read the description of Ext.Element in the ExtJS document for yourself. I will not extract it.
First give me an html code for demonstration purposes

Copy the code The code is as follows:




I'm a div ==> my id: bar, my class: foo
I'm a span within the div with a foo class
An ExtJs link


my id: foo, my class: bar

I'm a P tag within the foo div


I'm a span within the div with a bar class> ;
An internal link

BlueLotus7@126.com
> ;



(1) Take according to the tag: // This query will return an array with two elements because the query selects the entire All span tags of the document.
Ext.query("span");
// This query will return an array with one element because the query takes into account the id foo.
Ext.query("span", "foo"); // This will return an array with one element, the content is the p tag under the div tag
Ext.query("div p");
// This will return an array with two elements, the content is the span tag under the div tag
Ext.query("div span"); (2) Based on ID: // This query will return the content containing our foo div an array of elements!
Ext.query("#foo"); //Or directly Ext.get("foo");(3) Get it according to the name of the class: Ext.query(".foo");//This query Will return an array of 5 elements.
Ext.query("*[class]"); // Result: [body#ext-gen2.ext-gecko, div#bar.foo, span.bar, div#foo.bar, span.bar] (4) Universal method to get: (You can use this method to get by id, name, class, css, etc.) // This will get all the elements whose class is equal to "bar"
Ext.query("*[class=bar" ]");
// This will get all elements whose class is not equal to "bar"
Ext.query("*[class!=bar]");
// This will get the class from " All elements starting with b"
Ext.query("*[class^=b]");
//This will get all elements whose class ends with "r"
Ext.query( "*[class$=r]");
//This will get all elements that extract the "a" character in class
Ext.query("*[class*=a]");// This will get all elements with name equal to "BlueLotus7"
Ext.query("*[name=BlueLotus7]");
Let's change the html code:
Copy code The code is as follows:






I am a div ==> My id is: bar, my class: foo
I'm a span within the div with a foo class
An ExtJs link with a blank target!


my id: foo, my class: bar

I'm a P tag within the foo div


I'm a span within the div with a bar class
An internal link




// Get all red elements
Ext.query("*{color=red}"); // [div#bar.foo]
// Get all pink elements with red color Elements of child elements
Ext.query("*{color=red} *{color=pink}"); // [span.bar]
// Get all elements that are not red text
Ext .query("*{color!=red}"); // [html, head, script firebug.js, link, body#ext-gen2.ext-gecko, script ext-base.js, script ext-core. js, span.bar, a www.extjs.com, div#foo.bar, p, span.bar, a test.html#]
// Get all elements whose color attribute starts from "yel"
Ext.query("*{color^=yel}"); // [a www.extjs.com]
// Get all elements whose color attributes end with "ow"
Ext.query( "*{color$=ow}"); // [a www.extjs.com]
// Get all elements whose color attribute contains the "ow" character
Ext.query("*{color*= ow}"); // [a www.extjs.com, span.bar]
(5) Change the pseudo operator method to html:
Copy code The code is as follows:





< ;div id="bar" class="foo" style="color:red; border: 2px dotted red; margin:5px; padding:5px;">
I am a div ==> my id It's bar, and my class is foo
Here is the span element, and the outer div element has the class attribute of foo
Set blank=target ExtJS link


The id here is : foo, the class here is the p element surrounded by bar

"foo" div.


Here is a span element, surrounded by divs on the outer layer, and span also has a class attribute of bar.
Built-in link



  • Item #1

  • Item #2 li>
  • Item #3

  • Item #4 with Link













First line , the first column The first row, the second column
The second row, cells have been merged!
Third row, first column Third row, Second column









//The SPAN element is the first child element of its parent element
Ext.query("span:first-child"); // [span.bar]
//The A element is its parent The last child element of the element
Ext.query("a:last-child") // [a www.extjs.com, a test.html#]
//The SPAN element is the third of its parent element 2 child elements (number starting from 1)
Ext.query("span:nth-child(2)") // [span.bar]
//TR element is an odd number of its parent element Number of child elements
Ext.query("tr:nth-child(odd)") // [tr, tr]
//LI element is an odd number of child elements of its parent element
Ext.query("li:nth-child(even)") // [li, li]
//Returns the A element, which is the only child element of its parent element
Ext.query("a :only-child") // [a test.html#]
//Return all checked (checked) INPUT elements
Ext.query("input:checked") // [input#chked on ]
//Return the first TR element
Ext.query("tr:first") // [tr]
//Return the last INPUT element
Ext.query(" input:last") // [input#notChked on]
//Return the second TD element
Ext.query("td:nth(2)") // [td]
/ /Return each DIV containing the "within" string
Ext.query("div:contains(within)") // [div#bar.foo, div#foo.bar]
//Return None Contains those DIVs other than FORM sub-elements
Ext.query("div:not(form)") [div#bar.foo, div#foo.bar, div]
//Returns the A element Those DIV collections
Ext.query("div:has(a)") // [div#bar.foo, div#foo.bar, div]
//Return those TDs that will continue to have TDs gather. One thing in particular is that if TD with the colspan attribute is used, it will be ignored
Ext.query("td:next(td)") // [td, td]
//Return the element that precedes the INPUT Those LABEL element collections
Ext.query("label:prev(input)") //[label, label]
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
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software