I want to build some function in JavaScript, that sends text from textarea
to a div
.
I want it do the following
If the user tries to send html source to a textarea, it will show the text, and not the actual html source.
For example:
If the user tries to send: <img src='aa.png'>
I want to see in the div the text: <img src='aa.png'>
, and don't want to see the actual image: aa.png
Use .innerText
or .textContent
instead of .innerHTML
eleme.innerText="<img src='aa.png'>";
where eleme
is your div
DEMO:
document.getElementById('test1').innerHTML="<img src='aa.png'>";
document.getElementById('test2').innerText="<img src='aa.png'>";
document.getElementById('test3').textContent="<img src='aa.png'>";
<div id="test1"></div>
<div id="test2"></div>
<div id="test3"></div>
You can read more for differences between this three commands and others Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With