Suppose I have a string <span class="msg">Text goes here</span>
.I need to use this string as a HTML element in my webpage. Any ideas on how to do it?
相关问题
- Views base64 encoded blob in HTML with PHP
- how to split a list into a given number of sub-lis
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
Mithril it's powerfull thanks to the virtual dom, in the view you if you want to create a html element you use:
So in your case:
Try creating a container you wish to hold your
span
in.1. Use jQuery to select it.
2. On that selection, call the jQuery
.html()
method, and pass in your HTML string.(
$('.container').html(//string-goes-here)
, for example)You should be able to assign the inner HTML of the container with the string, resulting in the HTML element you want.
Docs here.
Mithril provides the
m.trust
method for this. At the place in your view where you want the HTML output, writem.trust( '<span class="msg">Text goes here</span>' )
and you should be sorted.