I want to store javascript code in a javascript variable. To explain clearly, please consider example:
<html>
<body>
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
//-->
</script>
<a onclick="toggle_visibility('1');toggle_visibility('2');">Click here to toggle visibility of element </a>
<div id="1">This is 1</div>
<div id="2">This is 2</div>
<script type="text/javascript">
//document.getElementById('2').style.display='none';
</script>
</body>
</html>
Now suppose all this code is in a variable as a string or something. (i want to do this because i am exporting file to another html page where the code should get copied.) I used all variables such as using \ before ' and so on. referring to http://www.w3schools.com/js/js_special_characters.asp