I am developing a small editor to add widgets (HTML, CSS and Javascript) to a site.
- The user types into a field the widget code.
- When validating, the code of the widget is added to the page.
- The user can edit the code (which is retrieved from the DOM).
Except that I have a problem to retrieve the javascript code. Indeed, it is well executed, but disappears from the DOM. There is something that escapes me!
I simplified my problem here: HTML code:
<textarea id="code">
<script type="text/javascript">alert("code");</script>
</textarea>
<div id="target"></div>
Javascript code:
$("#target").html($("#code").val());
alert($("#target").html());
Try it out : http://jsfiddle.net/8uhB8/3/
This example insert javascript code (a simple javascript alert) and tries to retrieve it.
Do you have any idea?
Thanks!