PHPackages                             perry-rylance/dom-document - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. perry-rylance/dom-document

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

perry-rylance/dom-document
==========================

An extension of PHP's DOMDocument library. This library implements many common jQuery functions, adds support for HTML5, CSS selectors, method chaining and performing operations on sets of matched results.

3.0.1(2y ago)17.8k3[9 issues](https://github.com/PerryRylance/DOMDocument/issues)[2 PRs](https://github.com/PerryRylance/DOMDocument/pulls)1MITPHPPHP &gt;=8.2.0

Since Jul 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/PerryRylance/DOMDocument)[ Packagist](https://packagist.org/packages/perry-rylance/dom-document)[ Docs](https://perryrylance.com)[ RSS](/packages/perry-rylance-dom-document/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (5)Versions (28)Used By (1)

DOMDocument
===========

[](#domdocument)

An extension of PHP's DOMDocument library. This library implements many common jQuery functions, adds support for HTML5, CSS selectors, method chaining and performing operations on sets of matched results.

IMPORTANT NOTICE - The future of this library
---------------------------------------------

[](#important-notice---the-future-of-this-library)

With the release of PHP 8.4's [new DOM features](https://www.php.net/manual/en/migration84.new-features.php#migration84.new-features.dom), the core features of this package are now supported natively, that is, HTML5 and CSS selectors.

Whilst this library is still compatible, if there are any future versions then I will be handing over this functionality to PHP's new DOM classes.

I have experimented with the new version and as far as I can tell there is now no means to register our own classes as extensions of the built in node class. The `HTMLDocument` is `final` and I cannot see any documented way to register node classes. With that said, the documentation hasn't been updated yet, neither has Intelephense seemingly.

I will wait until the documentation has been updated and then decide whether this package will be deprecated or not. I may also take this library in a different direction such as providing a single jQuery like function to manipulate documents without touching or extending the built in implementation.

Please watch this space!

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2.0
- Composer

Installation
------------

[](#installation)

I recommend installing this package via Composer.

`composer require perry-rylance/dom-document`

Usage
-----

[](#usage)

Instantiate DOMDocument and enjoy the jQuery-like functions now at your disposal.

As of version 2.0.0, this library does not add jQuery-like methods to DOMElement, in order to avoid future collisions with the HTML living standard spec. Rather, these jQuery-like methods are implemented on `DOMObject` in the same manner jQuery objects work.

Documentation
-------------

[](#documentation)

Read the libraries [documentation](https://perryrylance.github.io/DOMDocument/).

The requirements to generate documentation are as follows:

- `phpDocumentor` must be [installed](https://docs.phpdoc.org/guide/getting-started/installing.html#installation).

To generate documentation, use the following command.

`php  -t ./docs --ignore vendor/`

Testing &amp; Development
-------------------------

[](#testing--development)

As of 3.0.0, tests are run via Docker to facilitate cross PHP version testing.

All tests can be run by running `tests.sh`.

To run individual tests from your native CLI:

`docker-compose run php82 php /app/vendor/bin/phpunit tests --filter=testCastToString`

Migrating from 2.\* to 3.\*
---------------------------

[](#migrating-from-2-to-3)

Version 2.\* is not compatible with PHP 8.3, version 3.0.0 addresses this.

### Breaking changes

[](#breaking-changes)

- The static method `contains` has moved from `DOMElement` to `DOMObject`, because as of 8.3 `contains` is implemented as a non-static method on `DOMElement`.
- The methods `load` and `loadHTML` now take integer flags as options and return boolean. This is to satisfy function signatures being the same as PHP's native `DOMDocument` in future versions.

Migrating from 2.0.\* to 2.1.\*
-------------------------------

[](#migrating-from-20-to-21)

### Breaking changes

[](#breaking-changes-1)

- `first()` and `last()` now return a `DOMObject` instead of a `DOMElement`.

Migrating from 1.0.\* to 2.\*
-----------------------------

[](#migrating-from-10-to-2)

If you are considering switching from 1.0.\* to &gt;= 2.0.0 please note there are some considerations to be aware of.

### Moved methods

[](#moved-methods)

Many, many methods which were previously implemented on `DOMElement` are now on `DOMObject`. This helps avoid collisions with PHP's native `DOMElement` as more convenience methods are added there, like in the recent RFC sprint.

### Avoid querySelector

[](#avoid-queryselector)

The method `querySelector` is still implemented and publicly visible for internal reasons, however, I'd recommend avoiding using this method.

Any code which did expect a single `DOMElement` from `querySelector` may now create fatal errors.

`DOMDocument::querySelector` now returns a `DOMObject` in an effort to make *almost* all common methods still available and keep old code stable, however, some methods (such as `isBefore`) are not implemented by `DOMObject`. These methods are intended for internal use. Documentation will be updated to reflect this.

### Static contains

[](#static-contains)

`DOMElement::contains` is now static, in line with jQuery's design pattern. This may create warnings for users migrating from older versions.

### PHP requirement

[](#php-requirement)

This library has *dropped support* for PHP &lt; 8.2.0 in version &gt;= 3.0.0.

### Enhanced manipulation

[](#enhanced-manipulation)

Many methods, such as `append`, `prepend`, `before`, `after`, `wrap`, and many others, now support passing in an entire array or `DOMObject` as an argument.

This can be used to append content to multiple elements, where there is more than one element in the set.

If the target set contains only one element, then the same elements passed into these functions will be added to the DOM tree.

If the target set contains multiple elements, then the input elements will be cloned - please note that manipulating the input set after performing these operations may not affect the DOM tree, because the new content is cloned from the input set.

Support
-------

[](#support)

Please feel free to open issues here or submit pull requests.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance11

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~107 days

Total

24

Last Release

742d ago

Major Versions

1.0.14 → 2.0.02021-05-16

2.3.0 → 3.0.02024-04-28

PHP version history (6 changes)1.0.1PHP ^5.4

1.0.2PHP ^5.4.0

1.0.3PHP &gt;=5.4.0

2.0.0PHP &gt;=7.0.0

2.2.0PHP &gt;=7.4.0

2.3.0PHP &gt;=8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/35a517d8044830b0a015a9b7284ce900de922292ac8298b5b6320354cd19f470?d=identicon)[PerryRylance](/maintainers/PerryRylance)

---

Top Contributors

[![PerryRylance](https://avatars.githubusercontent.com/u/14136738?v=4)](https://github.com/PerryRylance "PerryRylance (106 commits)")[![warhuhn](https://avatars.githubusercontent.com/u/2159656?v=4)](https://github.com/warhuhn "warhuhn (1 commits)")

---

Tags

HTML5dom

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/perry-rylance-dom-document/health.svg)

```
[![Health](https://phpackages.com/badges/perry-rylance-dom-document/health.svg)](https://phpackages.com/packages/perry-rylance-dom-document)
```

###  Alternatives

[desandro/masonry

Cascading grid layout library

16.7k424.4k1](/packages/desandro-masonry)[desandro/imagesloaded

JavaScript is all like \_You images done yet or what?\_

8.9k439.0k1](/packages/desandro-imagesloaded)[wa72/htmlpagedom

jQuery-inspired DOM manipulation extension for Symfony's Crawler

3383.9M34](/packages/wa72-htmlpagedom)[kartik-v/yii2-widget-colorinput

An enhanced Yii 2 widget encapsulating the HTML 5 color input (sub repo split from yii2-widgets)

324.8M10](/packages/kartik-v-yii2-widget-colorinput)[kartik-v/yii2-widget-rangeinput

An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

193.9M3](/packages/kartik-v-yii2-widget-rangeinput)[silverstripe/html5

HTML5 support for SilverStripe

16232.6k4](/packages/silverstripe-html5)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
