Through DOM tree, we can get the types of HTML tags as follows:
1. Using document objects to get HTML tags
You can get the elements in an HTML document through the document object.
2. Use the nodeType property of DOM node to get the HTML tag type. NodeType attribute of DOM node indicates the type of node, and different types correspond to different numbers. The HTML tag is represented as 1 in the DOM tree, so the type of the HTML tag can be judged.
3. use the instanceof keyword to determine whether it is an HTMLElement object. HTMLElement is an interface representing HTML elements in JavaScript, and instanceof can be used to determine whether an element is an HTMLElement object.
It should be noted that the above method obtains the original HTML tag types, such as div, span and so on. , excluding specific attributes such as class and id. If you need to get the class and id attributes of an element, you need to use other methods.
Large-scale open online courses. Com has an excellent team of lecturers, most of whom are celebrities in the industry. The lecturer's explanation is concise and clear, and the cases are vivid, which can help students better understand the course content.