PHPackages                             devvoh/simpledom - 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. devvoh/simpledom

ActiveLibrary

devvoh/simpledom
================

SimpleDom just makes it a little easier to work with the DOM in PHP

0.1.1(8y ago)238MITPHPPHP &gt;=5.6

Since Dec 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/devvoh/simpledom)[ Packagist](https://packagist.org/packages/devvoh/simpledom)[ Docs](https://github.com/devvoh/simpledom)[ RSS](/packages/devvoh-simpledom/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

SimpleDom
=========

[](#simpledom)

[![Build Status](https://camo.githubusercontent.com/a7afd43c520561cb7ed99163391cc5fedf73d97e324be93cd4adcc6fc0656c04/68747470733a2f2f7472617669732d63692e6f72672f646576766f682f73696d706c65646f6d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/devvoh/simpledom)[![Latest Stable Version](https://camo.githubusercontent.com/d5ff6e9b66ae638e1b72ab820183574150e7028249b38b7d812efa31461ed7aa/68747470733a2f2f706f7365722e707567782e6f72672f646576766f682f73696d706c65646f6d2f762f737461626c65)](https://packagist.org/packages/devvoh/simpledom)[![Latest Unstable Version](https://camo.githubusercontent.com/96116bdcefc587e8a75850cd8df2b747beec111ab518262d5a5c01d818ee970e/68747470733a2f2f706f7365722e707567782e6f72672f646576766f682f73696d706c65646f6d2f762f756e737461626c65)](https://packagist.org/packages/devvoh/simpledom)[![License](https://camo.githubusercontent.com/db6ecc86325522ec44bde98eddc4e4c16f874a3a0b8eb9c4027b8ae35668f8a0/68747470733a2f2f706f7365722e707567782e6f72672f646576766f682f73696d706c65646f6d2f6c6963656e7365)](https://packagist.org/packages/devvoh/simpledom)

SimpleDom adds simple class manipulation to DOMDocuments and DOMElements.

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

[](#requirements)

- PHP 5.6+
- Composer

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

[](#installation)

SimpleDom can be installed by using [Composer](http://getcomposer.org/). Simply run:

`composer require devvoh/simpledom`

Usage
-----

[](#usage)

SimpleDom can be considered a facade adapter for the built-in `DOMDocument` and `DOMElement` classes. As such, you can use them anywhere you currently use those.

Creating a new instance is done with an extra step, however:

```
$domDocument = new \DOMDocument();
$domDocument->loadHTML($htmlString);

$document = \SimpleDom\Document::fromDOMDocument($domDocument);
```

To then get all elements with the class "header":

```
$elements = $document->getElementsByClassName("header");
```

And you'll get an array of `\SimpleDom\Element` items. SimpleDom also overwrites the following `DOMDocument` methods: `getElementsByTagName()`, `getElementById()` and `createElement()`.

Normally the `getElement` methods would return a `DOMNodeList` but SimpleDom returns an array of elements instead.

It's also possible to get elements which have multiple classes.

```
$elements = $document->getElementsByClassNames(["header", "sub"]);
```

Which will only return items that have both the "header" and "sub" class. The order of which is not important.

To get the DOMDocument back so you can save the HTML, simply do this:

```
$domDocument = $document->getDOMDocument();
echo $domDocument->saveHTML();
```

SimpleDom `Element` instances have some added features as well.

```
$element = $document->createElement("span", "this is a span!");
$element->addClass("blue");
```

The above code will result in the following html: `this is a span!`

The following methods are available to work with classes and Elements:

- `getClasses(): array`
- `setClasses(array): Element`
- `hasClass(string): bool`
- `hasClasses(array): bool`
- `addClass(string): Element`
- `addClasses(array): Element`
- `removeClass(string): Element`
- `removeClasses(array): Element`
- `toggleClass(string): Element`
- `toggleClasses(array): Element`
- `clearClasses(): Element`

Contact
-------

[](#contact)

All questions can be asked through github. Just create an issue and I'll get back with an answer as soon as possible.

License
-------

[](#license)

Devvoh SimpleDom is open-sourced software licensed under the MIT license.

###  Health Score

23

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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 ~0 days

Total

2

Last Release

3006d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7db40df70c77a9d591de4521642b0ddcb6c448e4876b22dc2f76900c736ab579?d=identicon)[robindevoh](/maintainers/robindevoh)

---

Tags

libraryhtmldom

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/devvoh-simpledom/health.svg)

```
[![Health](https://phpackages.com/badges/devvoh-simpledom/health.svg)](https://phpackages.com/packages/devvoh-simpledom)
```

###  Alternatives

[desandro/masonry

Cascading grid layout library

16.7k421.0k1](/packages/desandro-masonry)[desandro/imagesloaded

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

8.9k435.5k1](/packages/desandro-imagesloaded)

PHPackages © 2026

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