DOM notes (3): Element interface and HTMLElement interface_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:52:32
Original
1248 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template