Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I create an element? #16

Closed
marlun78 opened this issue Nov 3, 2015 · 2 comments
Closed

How do I create an element? #16

marlun78 opened this issue Nov 3, 2015 · 2 comments

Comments

@marlun78
Copy link

marlun78 commented Nov 3, 2015

Hi! Using domUtils.replaceElement(element, ???), how can I create a new element to replace with? I'm looking for something like domUtils.createElement('div', { id: 'some-id' }) or equivalent.
Thanks!

@jasonroyle
Copy link

Use htmlparser2 to parse an HTML string and then replace the element with the result.

var html = '<div id="some-id"></div>';
var domHandler = new DomHandler(function(err, elems) {
  DomUtils.replaceElement(elem, elems[0]);
});
var parser = new HTMLParser.Parser(domHandler);
parser.write(html);
parser.end();

@fb55 fb55 closed this as completed Oct 16, 2017
@arcanis
Copy link

arcanis commented Apr 1, 2023

import {Element} from 'domhandler';

const el = new Element(`div`, {id: `some-id`});

It feels like Element should be re-exported, though ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants