[php-src] Issue #11688: Helper functions for DOM manipulation and CSS classes
| From: | dtdesign | Date: | Wed, 12 Jul 2023 12:01:37 +0000 |
| Subject: | [php-src] Issue #11688: Helper functions for DOM manipulation and CSS classes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244954@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11688
Author: dtdesign
### Description
The DOM extension of PHP lacks a couple of helper functions that have eased the life of frontend
engineers for many years.
The lack of a proper handling of CSS classes was painful back in the IE6 days and while jQuery
solved that to some degree, the addition of the
[
.classList](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) was a
massive improvement. I would really love to see PHP adding support for a similar interface to ease
the work with CSS classes.
Another improvement would be the addition of
[append()](https://developer.mozilla.org/en-US/docs/Web/API/Element/append),
[after()](https://developer.mozilla.org/en-US/docs/Web/API/Element/after),
[before()](https://developer.mozilla.org/en-US/docs/Web/API/Element/before) and
[insertAdjacentElement()](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentElement).
The first three functions are also special because they implicitly convert strings into text nodes.
after() and before() are simple helper functions that improve readability
instead of relying on some insertBefore() shenanigans on the parent element.
insertAdjacentElement() is unique as it accepts a string (in PHP this would possibly be
an enum?) for the position which itself can be the result of a simple match statement.
There is also
[replaceWith()](https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith)
that allows to swap out DOM nodes while preserving the original position in the DOM, but its
arguably more niche of a use case.