dart-lang / html

Dart port of html5lib. For parsing HTML/HTML5 with Dart. Works in the client and on the server.

Home Page:https://pub.dev/packages/html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I get an element's html without its content ?

TheCarpetMerchant opened this issue · comments

I'd like to have only the html of the node itself, without its children. So <div class="content"><p>text</p></div> would give me <div class="content"></div>.

You can do it like:

final el = doc.querySelector('div.content');
print(el?.clone(false).outerHtml);

Ah, didn't know about this clone function. Thank you !