how do I use the node Builder from Scriptacolus to insert html
-
09-06-2019 - |
Question
for example this code
var html = "<p>This text is <a href=#> good</a></p>";
var newNode = Builder.node('div',{className: 'test'},[html]);
$('placeholder').update(newNode);
casues the p and a tags to be shown, how do I prevent them from being escaped?
Solution
The last parameter to Builder.node is "Array, List of other nodes to be appended as children" according to the Wiki. So when you pass it a string it is treated like text.
You could use:
var a = Builder.node('div').update("<a href='#'>foo</a>")
Where the link is text or:
var a = Builder.node('div', {'class':'cool'},
[Builder.node('div', {'class': 'another_div'})]
);
And you could use just Prototypes new Element() (Available as of version 1.6).
var a = new Element('div').insert(
new Element('div', {'class': 'inner_div'}).update("Text in the inner div")
);
OTHER TIPS
You can use this solution: http://sviudes.blogspot.com/2009/08/como-usar-etiquetas-html-con.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow