How can I display the HTML content of a Text Area within a DIv AS HTML content and not text?
17,392
Solution 1
Something like the below should do it
$('your-container').html($('#about').val());
Hope this helps
Solution 2
Use .html() for placing content as html.
$('#show').click(function() {
$('#Preview').html($('#about').val());
});
Solution 3
<textarea id="about" rows="2" name="about" cols="20" aria-hidden="true"><p>test</p></textarea>
<div id='displayAbout'>ale</div>
<input type="button" id='preview' name="Preview" value="Preview">
Buffer is useless:
$("#preview").click(function() {$('#displayAbout').html($('#about').val());});
Author by
William Calleja
I'm a Web developer based in Malta interested in developing my own controls.
Updated on June 04, 2022Comments
-
William Calleja almost 2 years
I have the following markup:
<input id="displayBuffer" type="hidden"> <textarea id="about" rows="2" name="about" cols="20" aria-hidden="true"><p>test</p></textarea> <input type="button" onclick="javascript: $('#displayBuffer').val($('#about').html()); $('#displayAbout').html(unescape($('#displayBuffer').val()));" name="Preview" value="Preview">
When the 'preview' button is clicked the div is populated with the content of the 'about' text area however it is not being encoded as HTML but it's displaying
<p>test</p>
when I want it to displaytest
with whatever style I have in CSS forp
.What am I doing wrong?
-
William Calleja almost 12 yearsThanks mate, apparently my problem was that I was using .html() withthin the container's .html(). Using .val() as you suggested solved the problem.