Skip to content

Walk from root through all children - change Attributes #50

@SarahTrees

Description

@SarahTrees

I come from simplehtmldom and have found your library, thank you very much for OpenSource!

I need to go through all the elements in parent-child order, recursively. I really like how easy it is to read and change attributes with this library.

$dom= new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
<div class="row">
       <div class="col-6" data-attr="redcolumn">
              <div class="row">
                      <div class="col-10" data-attr="bluecolumn"><p>Text in a p</p></div>
              </div>
       </div>
</div>');

When starting I can start with
$dom->querySelectorAll('body > *'),
because my fragments are automatically integrated into a body by the library.
But how do I get all the direct divs which are included in my current elemts and not all the divs which are children of the children of the children ... ?

Per $childElement->querySelectorAll('*') I get all objects, not only the direct children - but I can very well read their attributes.
Per $childElement->childNodes I get the direct children, but I can't read their attributes, because the result is an object from the DOMParster, right? Is it possible to convert DomNode elements into HTML5DomNode objects?

Thank you for the support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions