Reputation: 1001
I have a page to show a log file, sometimes the log file contains some html tags and they make my page run slower since the tags are converted to contents like pictures etc., I want to disable that, so my goal is to show those tags as texts only, they should never be converted to contents.
This is the jquerythat I use:
<script type="text/javascript">
$(document).ready(function() {
setInterval(function() {
$.ajax({
url: "ssh.log",
success: function(result) {
$("#ssh").html(result);
}
});
var textarea = document.getElementById("ssh");
textarea.scrollTop = textarea.scrollHeight;
}, 1000);
});
</script>
And my div
looks like this:
<div id="ssh"></div>
How can I accomplish that?
Upvotes: 1
Views: 158
Reputation: 9060
Use .text()
to render content as a text:
$("#ssh").text(result);
Upvotes: 4
Reputation: 1793
As the previous answers have said, use .text()
to render it as just plaintext. If for some reason you need to keep it as .html()
, you can use simple string replacement to escape the tags.
result = result.replace('<','<');
$('#ssh').html(result);
Upvotes: 1
Reputation: 5571
Change:
$("#ssh").html(result);
to
$("#ssh").text(result);
Upvotes: 3