Reputation: 936
use html_parser::Dom;
let html = r#"<span class="text_editor"><h1 title="title is here">hello world</h1><p>hi paragraph</p></span>"#;
let nodes = Dom::parse(html).unwrap_throw();
// add the html
let doc = window().unwrap_throw().document().unwrap_throw();
let my_dom_element = &doc.get_element_by_id("1").unwrap_throw();
my_dom_element.append_child(&nodes.children[0]).unwrap_throw();
31 | my_dom_element.append_child(&nodes.children[0]).unwrap_throw();
| ^^^^^^^^^^^^^^^^^ expected struct `web_sys::Node`, found enum `html_parser::Node`
Upvotes: 0
Views: 1463
Reputation: 936
use web_sys::{window};
let doc = window().unwrap_throw().document().unwrap_throw();
let my_dom_element = &doc.get_element_by_id("1").unwrap_throw();
let html = r#"<span class="text_editor"><h1 title="title is here">hello world</h1><p>hi paragraph</p></span>"#;
my_dom_element.set_inner_html(html);
Upvotes: 0