Prevent Javascript Execution in JQuery html()

Posted by Mahan on Stack Overflow See other posts from Stack Overflow or by Mahan
Published on 2012-07-07T09:08:48Z Indexed on 2012/07/07 9:15 UTC
Read the original article Hit count: 195

Filed under:
|
|
|

well i do have a div that contains some more html and a lot of javascript on it

<div id="mydiv">
<p>Hello Philippines</p> my first time in Philippines is nice
<script type="text/javascript">alert("how was it became nice?");</script>
well i experienced a lot of things
<script type="text/javascript">alert("and how about your Japan's trip?");</script>
well its more nicer ^^ but both countries are good! hahah
</div>

now what i want there is to put the non-javascript code and javascript code in two separate variables

var html = $("#mydiv").html();

but my problem here is my javascript is executing..which makes me stop to create the code i want which is the storing of javascript and non-javascript to two different variables.

now my questions is

  1. how can i stop the javascript codes from executing when they are get inside the div?
  2. how can i store the javascript and non-javascript code into two different variables safely?

NOTE: i need the stored javascript for later execution

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery