PHPackages                             sekonda/dom-query - 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. sekonda/dom-query

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

sekonda/dom-query
=================

PHP PowerTools DOM-Query Component

05PHP

Since Oct 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Sekonda/DOM-Query)[ Packagist](https://packagist.org/packages/sekonda/dom-query)[ RSS](/packages/sekonda-dom-query/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

DOM Query Component
===================

[](#dom-query-component)

***[PHPPowertools](https://github.com/PHPPowertools)*** is a web application framework for PHP &gt;= 5.4.

***[PHPPowertools/DOM-Query](https://github.com/PHPPowertools/DOM-Query)*** is the first component of the ***PHPPowertools*** that has been released to the public.

The purpose of this component is to provide a ***[jQuery](http://jquery.com/)***-like interface for crawling XML and HTML documents. Under the hood, it uses ***[symfony/CssSelector](https://github.com/symfony/CssSelector)*** for converting ***[CSS selectors](http://www.w3.org/TR/CSS/)*** to ***[XPath queries](http://www.w3.org/TR/xpath/)***

---

##### The jQuery way :

[](#the-jquery-way-)

```
// Find the elements that match selector 'div.foo'
$s = $('div.foo');

// Pass an element object (DOM Element)
$s = $(document.body);

// Pass a jQuery object
$s = $($('p + p'));
```

##### The DOM-Query way :

[](#the-dom-query-way-)

```
namespace App;
use \PowerTools\DOM_Query;

// Get file content
$htmlcode = file_get_contents('https://github.com');

// Create a new DOM_Query instance, using a string as a source
$H = new DOM_Query($htmlcode);

// Create a new DOM_Query instance, using an existing DOM_Query instance as a source
$H = new DOM_Query($H->select('body'));

// Find the elements that match selector 'div.foo'
$s = $H->select('div.foo');

// Pass an element object (DOM Element)
$s = $H->select($documentBody);

// Pass a DOM Query instance
$s = $H->select($H->select('p + p'));
```

---

##### Example use :

[](#example-use-)

```
// Select the body tag
$body = $H->select('body');

// Combine different classes as one selector to get all site blocks
$siteblocks = $body->select('.site-header, .masthead, .site-body, .site-footer');

// Nest your methods just like you would with jQuery
$siteblocks->select('button')->add('span')->addClass('icon icon-printer');

// Use a lambda function to set the text of all site blocks
$siteblocks->text(function($i, $val) {
    return $i . " - " . $val->attr('class');
});

// Append the following HTML to all site blocks
$siteblocks->append('');

// Use a descendant selector to select the site's footer
$sitefooter = $body->select('.site-footer > .site-center');

// Set some attributes for the site's footer
$sitefooter->attr(array('id' => 'aweeesome', 'data-val' => 'see'));

// Use a lambda function to set the attributes of all site blocks
$siteblocks->attr('data-val', function($i, $val) {
    return $i . " - " . $val->attr('class') . " - photo by Kelly Clark";
});

// Select the parent of the site's footer
$sitefooterparent = $sitefooter->parent();

// Remove the class of all i-tags within the site's footer's parent
$sitefooterparent->select('i')->removeAttr('class');

// Wrap the site's footer within two nex selectors
$sitefooter->wrap('');

[...]
```

---

##### Supported methods :

[](#supported-methods-)

- [$](http://api.jquery.com/jQuery/) *(1)*
- [$.parseHTML](http://api.jquery.com/jQuery.parseHTML/)
- [$.parseXML](http://api.jquery.com/jQuery.parseXML/)
- [$.parseJSON](http://api.jquery.com/jQuery.parseJSON/)
- [$selection.add](http://api.jquery.com/add/)
- [$selection.addClass](http://api.jquery.com/addClass/)
- [$selection.after](http://api.jquery.com/after/)
- [$selection.append](http://api.jquery.com/append/)
- [$selection.attr](http://api.jquery.com/attr/)
- [$selection.before](http://api.jquery.com/before/)
- [$selection.children](http://api.jquery.com/children/)
- [$selection.closest](http://api.jquery.com/closest/)
- [$selection.contents](http://api.jquery.com/contents/)
- [$selection.detach](http://api.jquery.com/detach/)
- [$selection.each](http://api.jquery.com/each/)
- [$selection.eq](http://api.jquery.com/eq/)
- [$selection.empty](http://api.jquery.com/empty/) *(2)*
- [$selection.find](http://api.jquery.com/find/)
- [$selection.first](http://api.jquery.com/first/)
- [$selection.get](http://api.jquery.com/get/)
- [$selection.hasClass](http://api.jquery.com/hasclass/)
- [$selection.insertAfter](http://api.jquery.com/insertAfter/)
- [$selection.insertBefore](http://api.jquery.com/insertBefore/)
- [$selection.is](http://api.jquery.com/is/)
- [$selection.last](http://api.jquery.com/last/)
- [$selection.parent](http://api.jquery.com/parent/)
- [$selection.parents](http://api.jquery.com/parents/)
- [$selection.remove](http://api.jquery.com/remove/)
- [$selection.removeAttr](http://api.jquery.com/removeAttr/)
- [$selection.removeClass](http://api.jquery.com/removeClass/)
- [$selection.text](http://api.jquery.com/text/)
- [$selection.wrap](http://api.jquery.com/wrap/)

---

1. *Renamed 'select', for obvious reasons*
2. *Renamed 'void', since 'empty' is a reserved word in PHP*

---

##### Author

[](#author)

[![twitter/johnslegers](https://camo.githubusercontent.com/3f588c061f691c1a18db125c956f40ad3796061291c66ea5a54536e255403aa4/68747470733a2f2f656e2e67726176617461722e636f6d2f6176617461722f62663463633934323231333832383130323333353735383632383735653638373f733d3730)](http://twitter.com/johnslegers "Follow @johnslegers on Twitter")[John slegers](http://www.johnslegers.com/)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c0653c168e81a8692e359108d9d7a40fc6d00b7a42e1b37488de4ac1d5d9181?d=identicon)[Sekonda](/maintainers/Sekonda)

---

Top Contributors

[![jslegers](https://avatars.githubusercontent.com/u/883647?v=4)](https://github.com/jslegers "jslegers (43 commits)")[![Ambient-Impact](https://avatars.githubusercontent.com/u/2289006?v=4)](https://github.com/Ambient-Impact "Ambient-Impact (9 commits)")[![simondotwhite](https://avatars.githubusercontent.com/u/793770?v=4)](https://github.com/simondotwhite "simondotwhite (1 commits)")

### Embed Badge

![Health badge](/badges/sekonda-dom-query/health.svg)

```
[![Health](https://phpackages.com/badges/sekonda-dom-query/health.svg)](https://phpackages.com/packages/sekonda-dom-query)
```

PHPackages © 2026

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