Differences between dojo. query-query (ID) and query (class) in Dojo learning notes

Source: Internet
Author: User

Consider this example: When a page is dynamically created, multiple listitems are generated using new listtem (), and each listitem generates a button.

Assuming that you want to bind a click event to each button, it is easier to use dojo. query to obtain these buttons than compile.

In this case, I encountered a problem. In the create button loop statements, I defined id = "somebtn" for each button ".

Then try to use VaR btnlist = dojo. Query ("# somebtn") to get an array that includes all buttons on the page.

Unfortunately, the query statement does not get all buttons. It only gets one button object. The input result of the console. Log (btnlist. Length) Statement is 1 and can be inferred.

Again look at the instructions in the http://dojotoolkit.org/reference-guide/1.9/dojo/query.html documentation, found that the sample is basically query (". someclass"), only use the class, and no practical ID.

So I have reviewed the differences between class and ID, and mentioned that ID is a unique identifier, which means that the ID in the page can only represent a unique element, then we can figure out why query (ID) can only get one element.

After adding the class attribute to the button, you can use query ("class") to obtain all the button objects.


When a problem occurs, you can roughly infer the problem through debugging, confirm the problem, and then check the document to remedy the problem. This is a summary of today.


Differences between dojo. query-query (ID) and query (class) in Dojo learning notes

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.