-4

I'm making my own IDE and I need a way of running code(HTML) from a JavaScript function call.

I have a div I need the user to click a button then the div will contain html which is from a textarea.

By RUNNING HTML CODE I mean to get input from a text area and dump it into a div so it it running in the div

(my IDE is by far the best workspace) My Workspace

Here is my CODE:`

<textarea class="txtarea"></textarea>

<div class="browser">A Browser</div>

<button class="run-btn">RUN</button>

<script>

var num = 0;
$(".browser").hide(); // hide my div
$(".run-btn").click(function() {
  num++;
  if (num % 2 == 1) {
    $(".txtarea").hide();
    $(".browser").show(); // my div
    $(".browser").text($(".txtarea").val());
  }
  if (num % 2 == 0) {
    $(".txtarea").show();
    $(".browser").hide();
  }
});


</script>
Zak The Hat
  • 317
  • 1
  • 5
  • 15

2 Answers2

0

I think you have to use an IFrame instead of a DIV to render your entered HTML code.

This questions shows how to create programmatically an IFrame containing your HTML code: Creating an iframe with given HTML dynamically

Community
  • 1
  • 1
Ehler
  • 285
  • 3
  • 11
0

I checked your code but I am not getting what is the issue. Everything is working fine.

binay37
  • 121
  • 1
  • 11