大网数据广告活动
PHP 语言与运行手册

The Dom\Element class

· 52CE 我爱测

This is the modern, spec-compliant equivalent of DOMElement.

The Dom\Element class

(PHP 8 >= 8.4.0)

简介

Represents an element.

This is the modern, spec-compliant equivalent of DOMElement.

类摘要

class Dom\Element extends Dom\Node implements Dom\ParentNode, Dom\ChildNode {
/* 继承的常量 */
/* 属性 */
public readonly ?string $namespaceURI;
public readonly ?string $prefix;
public readonly string $localName;
public readonly string $tagName;
public string $id;
public readonly Dom\TokenList $classList;
public readonly Dom\NamedNodeMap $attributes;
public readonly ?Dom\Element $lastElementChild;
public readonly int $childElementCount;
public readonly Dom\HTMLCollection $children;
/* 继承的属性 */
public readonly int $nodeType;
public readonly string $nodeName;
public readonly string $baseURI;
public readonly bool $isConnected;
public readonly ?Dom\Document $ownerDocument;
public readonly ?Dom\Node $parentNode;
public readonly ?Dom\Element $parentElement;
public readonly Dom\NodeList $childNodes;
public readonly ?Dom\Node $firstChild;
public readonly ?Dom\Node $lastChild;
public readonly ?Dom\Node $previousSibling;
public readonly ?Dom\Node $nextSibling;
/* 方法 */
public function getElementsByClassName(string $classNames): Dom\HTMLCollection
public function insertAdjacentHTML(Dom\AdjacentPosition $where, string $string): void
/* 继承的方法 */
/* Not documented yet */
}

属性

namespaceURI

The namespace URI of the element.

prefix

The namespace prefix of the element.

localName

The local name of the element.

tagName

The HTML-uppercased qualified name of the element.

className

A string representing the classes of the element separated by spaces.

classList

Returns an instance of Dom\TokenList to easily manage the classes on this element.

attributes

Returns an instance of Dom\NamedNodeMap that represents the attributes of this element.

id

Reflects the element ID through the "id" attribute.

firstElementChild

First child element or null.

lastElementChild

Last child element or null.

childElementCount

The number of child elements.

previousElementSibling

The previous sibling element or null.

nextElementSibling

The next sibling element or null.

children

A Dom\HTMLCollection containing all child elements of this node. Available as of PHP 8.5.0.

innerHTML

The inner HTML (or XML for XML documents) of the element.

outerHTML

The outer HTML (or XML for XML documents) of the element, including the element itself. Available as of PHP 8.5.0.

substitutedNodeValue

The node value with entity substitution enabled.

更新日志

版本 说明
8.5.0 Added the Dom\Element::getElementsByClassName() and Dom\Element::insertAdjacentHTML() methods.

注释

注意:

此 DOM 扩展在处理方法或属性时使用 UTF-8 编码。 解析器方法会自动检测编码,或允许调用者指定编码。

目录

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。