Technology sharing how to identify and control page elements in DHTML and JS

Source: Internet
Author: User

Do you know how to control every page element? Here we will give you a brief introduction to the recognition control of page elements in DHTML and JS. I believe you will be interested in it.

Identification Control of page elements in DHTML and JS

In the process of creating a dynamic web page, we often need to perform operations on the corresponding page elements, which requires us to be able to accurately control each page element.

Generally, elements in a webpage can be identified in multiple ways, such as context-based identification or element recognition.

There are three most common element identification methods in a webpage: ID, CLASS, and NAME. They are represented to a single element identity. CLASS is used to NAME the same type, while NAME is used to NAME a general element.

For example, you can name it as follows:

 
 
  1. <imgid="pic"src="..">  
  2. <spanname="kuai"></span>  
  3. <divclass="layer"></div> 

When we call these elements in JAVASCRIPT, we can use document. all. pic, document. all. kuai to identify them.

Generally, a name is only used for the name of an element, but it is not exactly the same. Sometimes elements of the same type must have the same effect, not only can they be identified by CLASS, you can also use the ID or NAME to identify all the identical IDs and names.
However, this poses a problem: how to identify an element.

In this case, the difference between recognition and single name recognition lies in the addition of digital indexes. For example, the previous pic can also use document. all. pic [1] is used for identification, and the others are identified by numbers in the order they appear on the page.

In many cases, the control function is triggered by the corresponding event, so we may use the element that triggers the event. In this case, we can use eventElement to identify the event, it indicates the element that triggers the event.

At the same time, parentElement and childrenElement can also be used to identify the upper-level and lower-level elements that trigger event elements.
When eventElement is used to obtain a trigger element, we can also obtain its identifier name. For example, if eventElement. tagName is used to obtain the HTML Identification name of the element, eventElement. id is used to obtain the name of the element, and eventElement. name is used to obtain the name of the element.

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.