question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Injecting strings with HTML content

See original GitHub issue

Is 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>&lt;div&gt;hi&lt;/div&gt;</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:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fraserxucommented, Mar 25, 2016

Is this one a good option for the use case here? sanitize-html

0reactions
ungoldmancommented, Mar 25, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found