Skip to content

Cannot replace root elements in html-fragment #65

@shtse8

Description

@shtse8
<p>Paragraph 1</p> <p>Paragraph 2</p><p>Paragraph 3</p>

As there is no root, how can I search the p and replace it?
I tired to use filter and replace, but it will remove all my matched elements.

$dom = FluentDOM::QueryCss('<p>Paragraph 1</p> <p>Paragraph 2</p><p>Paragraph 3</p>', 'html-fragment');
$dom->filter('p')->first()->each(function($element) {
	$element->replace('hi');
});
echo $dom;

Expected:

hi <p>Paragraph 2</p><p>Paragraph 3</p>

Actual:

 <p>Paragraph 2</p><p>Paragraph 3</p>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions