HTML 5 DOM defines complex data types such as collections and lists for convenient operations. Compared with HTML 4 DOM, HTML 5 DOM adds HTMLCollection, DOMTokenList, DOMStringMap, HTMLAllCollection, HTMLFormControlsCollection, etc.
1. HTMLCollection, HTMLAllCollection and HTMLFormControlsCollection
The three interfaces are used to represent a list composed of a set of elements. Both HTMLAllCollection and HTMLFormControlsCollection inherit from the HTMLCollection interface and rewrite the namedItem() method defined in the HTMLCollection interface. In DOM Notes (1): HTMLDocument interface, use document.forms (/images/embeds, etc.) to return an HTMLCollection object, document.all returns an HTMLAllCollection object, and document.forms.elements returns an HTMLFormControlsCollection object, which contains All form elements in the form.
Attribute or method | Data type | Description | |||||||||||||||
length | long | Read-only, returns the number of elements in the collection. All three interfaces have this attribute | |||||||||||||||
item() | object | 1. Get the elements in the collection according to the index. Define
document.forms(0)document.forms[0]document.forms.item(0 )
| |||||||||||||||
tags() | HTMLAllCollection | Get elements based on tag names. Defined in HTMLAllCollection | |||||||||||||||
namedItem() | object | Get the elements in the collection based on the name or id attribute. The differences are as follows: 1. In HTMLCollection, first search based on name, then search based on id, but only return the first matching element. If there is no matching element, null is returned. The following equivalents exist: document.forms['formname']document.forms('formname')document.forms.namedItem('formname') 2. In HTMLAllCollection, if there are multiple matching elements, an HTMLCollection object is returned; if there is only one matching element, the element is returned. 3. In HTMLFormControlsCollection, if there are multiple matching elements, a RadioNodeList object is returned; if there is only one matching element, the element is returned.
|
2. HTMLOptionsCollection interface
This interface returns a list of elements. Different from HTMLCollection, It specifically returns a list of option elements and overrides the length attribute and namedItem() method. The data type returned by the HTMLSelectElement.options property is HTMLOptionsCollection.
属性或方法 | 数据类型 | 说明 |
length | long | 集合中标识的数量 |
value | DOMString | 获取或设置DOMTokenList值 |
add() | void | 插入一个标识 |
contains() | boolean | 判断是否包含某标识 |
remove() | void | 删除一个标识 |
item() | object | 根据索引获取标识 |
toggle() | boolean | 标识存在则删除,不存在则添加 |
toString() | DOMString | 返回对象的字符串形式 |
4. DOMStringMap and NodeList
The DOMStringMap interface marks a collection of "key/value pairs", and the key-value pairs can be deleted, modified, etc. through JavaScript syntax. In DOM Notes (3): Element interface and HTMLElement interface, the data type returned by the HTMLElement.dataset property is DOMStringMap
<html><head> <title>DOMStringMap</title></head><body> <img id="ex" data-ship-id="92432" data-x="30" data-y="10" data-z="90"/ alt="DOM notes (4): HTML 5 DOM complex data type_html/css_WEB-ITnose" > <script> var img = document.getElementById("ex"); //访问键值 alert(img.dataset.z); //设置键值 img.dataset.shipId="343434"; //创建新键值对 img.dataset.defend=100; //删除键值 delete img.dataset.y; </script></body></html>
NodeList interface represents a list composed of a series of nodes. document.getElementsByTagName() returns a NodeList object. It has a read-only length property, which is used to return the number of nodes; and an item() method, which is used to access nodes based on index. There are the following equivalent methods:
nodelist.item(0) nodelist[0]nodelist(0)

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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