Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the standard features in HTML Element

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to get the standard features in HTML Element". In daily operation, I believe many people have doubts about how to obtain the standard features in HTML Element. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to get the standard features in HTML Element". Next, please follow the editor to study!

In the process of interactive implementation, we often have to do some specified operations on DIV tags. There are many DIV tags in a document, so we must specify a hidden operation on a certain DIV, for example, if we want to find the object to be operated on, rather than all the DIV, then we can only determine it through the standard features in the attributes of DIV, such as getting the ID number of a DIV, or getting the class name, that is, ClassName. All HTML elements are represented by the HTMLElement type, not directly through this type. It is also represented by its subtypes. The HTMLElement type inherits directly from Element and adds some attributes. The added attributes correspond to the following standard features that exist in each HTML element.

Id, the unique identifier of the element in the document

Title, additional explanatory information about the element, usually displayed through the tooltip bar

Lang, the language code for element content, is rarely used

Dir, the direction of the language, with values of "ltr" (left-to-right, left to right) or "rtl" (right-to-left, right to left), and rarely used

ClassName, corresponding to the class attribute of the element, is the CSS class specified for the element. This property is not named class

Because class is a reserved word for ECMAScript.

All of these attributes can be used to obtain or modify the corresponding property values. Take the following HTML element as an example:

All the information specified in the element can be obtained through the following JavaScript code

Var div=document. GetElementByld ("myDiv")

Alert (div. Id); / / "myDiv"

Alert (div. ClassName); / / "bhClass"

Alert (div.title); / / "BaiHeng Test Text"

Alert (div. Lang); / / "en"

Alert (div. Dir); / / "ltr"

Of course, you can also modify each property by assigning a new value to each property as follows:

Div. Id= "someOtherld"

Div.className= "BHNewClass":

Div. Title= "http://www.jxbh.cn";

Div.

Div.dir = "rtl":

Not all changes to properties are intuitively displayed on the page. Changes to id or lang are transparent to the user (assuming there is no CSS style set based on their values), while changes to title are displayed only when the mouse moves over this element. Changes to dir will immediately affect the left and right alignment of the text in the page the moment the property is rewritten. When you modify the className, if the new class is associated with a different CSS style than the previous one, the new style is applied immediately.

At this point, the study on "how to get the standard features in HTML Element" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report