Injecting strings with HTML content
See original GitHub issueIs it possible to inject raw a HTML string into a bel element? Right now I can’t seem to get that working.
Example:
var bel = require('bel')
var html = '<div>hi</div>'
var body = bel`<div>${html}</div>`
document.body.appendChild(body)
try {
document.body.appendChild(bel`${html}`)
} catch (e) {
document.body.appendChild(bel`<div>${e.message}</div>`)
}
Output:
<div><div>hi</div></div>
<div>Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.</div>
http://requirebin.com/?gist=b7081814ea6465115d84
I’m trying to get this working for friends
(trying out a rewrite of the front-end using yo-yo
). Old method was to convert the html to a vdom element but that doesn’t apply in this instance since ain’t no vdom around. Here’s the part that’s causing the issue in friends if you’re curious: https://github.com/moose-team/friends/blob/master/lib/elements/messages.js#L44-L58
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Inject HTML From a String of HTML - CSS-Tricks
Say you have some HTML that is a string: let string_of_html = ` <div>Cool</div> `; Maybe it comes from an API or you've...
Read more >How can I inject a string of HTML into an element?
How can I inject a string of HTML into an element? ; inject: function(element, location) ; var foo = "<p>Some text</p>"; var ;...
Read more >Four different ways to inject text and HTML into an element ...
Today, we're going to look at four different techniques you can use to get and set text and HTML in DOM elements. Let's...
Read more >Injecting Strings as HTML into the DOM - YouTube
This tutorial covers the different methods that you can use to convert Strings into HTML and inject them into a webpage.
Read more >Safe Ways To Inject HTML Through JavaScript - TA Digital Labs
Introduction. This blog is about the safest techniques used to inject HTML markup through JavaScript on the web sites.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is this one a good option for the use case here? sanitize-html
I didn’t notice the wiki at all until after opening the last couple issues – sorry! I opted for creating a new wiki page: https://github.com/shama/bel/wiki/Working-with-HTML