The following method of embedding some Html from a string in a <div> with Javascript (using some JQuery) works:
var div = $('#someId');
var testHtml = '<script></script><div>dummy Content</div>';
div.html(testHtml);
The Html code gets embedded and displayed in the div. If I put some alert('Test')-statement in the <script> tags, the alert would show up.
What also works is this:
<div id="someId">@MvcHtmlString.Create("<script></script><div>dummy Content</div>")</div>
However I need to pass a MvcHtmlString to a javascript function and then embed this string with javascript.
This works if there is no javascript code inside the string:
var div = $('#someId');
var inputItem = '@MvcHtmlString.Create("<div>dummy Content</div>")';
div.html(inputItem);
However if there is javascript content inside the string, the <script>-part does not get embedded and the content doesn't get displayed properly.
So this doesn't work properly:
var div = $('#someId');
var inputItem = '@MvcHtmlString.Create("<script></script><div>dummy Content</div>")';
div.html(inputItem);
Can someone explain why this doesn't work? Is there a simple trick to it?