


DOM notes (3): Element interface and HTMLElement interface_html/css_WEB-ITnose
1. Element interface
The Element interface represents an element. This interface extends from the Node interface and naturally inherits the attributes and methods of the Node interface. It also has a set of attributes and methods for elements. method.
There are relatively few common attributes in the Element interface. The commonly used attribute is a read-only tagName attribute, which returns the element name and the data type is DOMString.
The methods defined by the Element interface are mainly for attribute operations. Common methods are as follows:
方法名 | 数据类型 | 说明 |
getAttribute | DOMString | 返回对应属性 |
getAttributeNode | Attr | 返回对应属性节点 |
getAttributeNodeNS | Attr | 返回属性命名空间 |
getAttributeNS | DOMString | 返回对应属性节点 |
getElementsByTagName | NodeList | 节点名获取元素列表 |
getElementsByTagNameNS | NodeList | 根据指定空间内的标签名搜索所有元素 |
hasAttribute | Boolean | 判断属性是否存在 |
hasAttributeNS | Boolean | 判断属性是否存在 |
removeAttribute | void | 删除属性 |
removeAttributeNode | Attr | 删除属性 |
removeAttributeNS | void | 删除属性 |
setAttribute | void | 添加属性 |
setAttributeNode | Attr | 添加属性节点 |
setAttributeNodeNS | Attr | 添加属性节点 |
setAttributeNS | void | 添加属性 |
2. HTMLElement interface
This interface is inherited from the Element interface and is also used to represent an HTML element with custom properties and methods.
1. Attribute list
属性名 | 数据类型 | 只读 | 说明 |
innerHTML | DOMString | 获取或设置HTML内容 | |
outerHTML | DOMString | 设置或获取对象的纯文本形式 | |
id | DOMString | 对应元素的id属性 | |
title | DOMString | 对应元素的title属性 | |
lang | DOMString | 对应元素的lang属性 | |
dir | DOMString | 对应元素的dir属性 | |
className | DOMString | 对应元素的class属性 | |
classList | DOMTokeList | Y | 返回元素的class属性作为DOMTokenList对象 |
dataset | DOMStringMap | Y | 返回自定义的data-*属性集合 |
hidden | Boolean | 对应元素的hidden属性 | |
tabIndex | long | 对应元素的tabIndex属性 | |
accessKey | DOMString | 对应元素的accessKey属性 | |
accessKeyLabel | DOMString | Y | 返回热键组合 |
draggable | Boolean | 对应元素的draggable属性 | |
contentEditable | DOMString | 对应元素的contentEditable属性 | |
isContentEditable | Boolean | Y | 判断元素是否可用编辑 |
contextMenu | HTMLMenuElement | 对应元素的contextMenu属性 | |
spellcheck | DOMString | 对应元素的spellcheck属性 | |
commandType | DOMString | Y | 对应元素的commandType属性 |
label | DOMString | Y | 对应元素的label属性 |
icon | DOMString | Y | 对应元素的icon属性 |
disabled | Boolean | Y | 对应元素的disabled属性 |
checked | Boolean | Y | 对应元素的checked属性 |
style | CSSStyleDeclaration | Y | 对应元素的style属性 |
2. Method list
方法名 | 数据类型 | 说明 |
getElementsByClassName | NodeList | 根据元素的class属性获取所有元素 |
insertAdjacentHTML | void | 在指定位置插入HTML或XML |
click | void | 单击元素,触发click事件 |
scrollIntoView | void | 滚动元素内容到视点内 |
focus | void | 元素获取焦点 |
blur | void | 元素失去焦点 |
Original article first published:
Next article :DOM Notes (4): HTML 5 DOM complex data types

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
