I have these HTML codes in 'body' tag:
<body>
<center>
Hello!<br />
<textarea cols="65" rows="10" id="code"></textarea>
</center>
</body>
And I want to place all of my page codes in above textarea with this codes in jQuery:
$("textarea#code").val( $('body').html() );
OK, now I want to let user change the HTML of 'body' in that 'textarea' using this:
$("textarea#code").change(function(){
$('body').html( $(this).val() );
$("textarea#code").val( $('body').html() );
});
After first change all things are OK and HTML changes successfully, but after doing that, the user can not change HTML for the second time! In other words, JavaScript didn't load.
Here's my snippet:
$("textarea#code").val( $('body').html() );
$("textarea#code").change(function(){
$('body').html( $(this).val() );
$("textarea#code").val( $('body').html() );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<center>
Hello!<br />
<textarea cols="65" rows="10" id="code"></textarea>
</center>
</body>