WP_HTML_Open_Elements::has_element_in_select_scopepublicWP 6.4.0

Returns whether a particular element is in select scope.

This test differs from the others like it, in that its rules are inverted. Instead of arriving at a match when one of any tag in a termination group is reached, this one terminates if any other tag is reached.

The stack of open elements is said to have a particular element in select scope when it has > that element in the specific scope consisting of all element types except the following: > - optgroup in the HTML namespace > - option in the HTML namespace

Method of the class: WP_HTML_Open_Elements{}

No Hooks.

Returns

true|false. Whether the given element is in SELECT scope.

Usage

$WP_HTML_Open_Elements = new WP_HTML_Open_Elements();
$WP_HTML_Open_Elements->has_element_in_select_scope( $tag_name ): bool;
$tag_name(string) (required)
Name of tag to check.

Notes

Changelog

Since 6.4.0 Introduced.
Since 6.4.0 Stub implementation (throws).
Since 6.7.0 Full implementation.

WP_HTML_Open_Elements::has_element_in_select_scope() code WP 7.0

public function has_element_in_select_scope( string $tag_name ): bool {
	foreach ( $this->walk_up() as $node ) {
		if ( $node->node_name === $tag_name ) {
			return true;
		}

		if (
			'OPTION' !== $node->node_name &&
			'OPTGROUP' !== $node->node_name
		) {
			return false;
		}
	}

	return false;
}