ElementNode::getAttribute

The getAttribute() method retrieves the value of the specified attribute for the current element. If the attribute does not exist, it returns null. This method is useful for accessing attributes such as id, class, or any other custom attribute defined in the HTML.

Description

public ElementNode::getAttribute(string $name): ?string

Parameters

name

The name of the attribute whose value is to be retrieved.

Return Value

Returns the value of the specified attribute as a string, or null if the attribute does not exist.

Exceptions

None

Source Code
If you find this project useful, consider leaving a on GitHub! Thank you!