Escape HTML tag in – user3243855 Jul 24 '14 at 10:40

  • 1
    http://stackoverflow.com/questions/3353129/jquery-escaping-html-from-a-textarea?rq=1 – Bhojendra Rauniyar Jul 24 '14 at 10:41
  • @putvande yes your right i can use that too !! Thanks :) – user3243855 Jul 24 '14 at 10:42
  • To verify, is this your problem? http://jsfiddle.net/mLeq7/ – Ron van der Heijden Jul 24 '14 at 10:44
  • @Bondye yes exactly.. – user3243855 Jul 24 '14 at 10:45
  • @user3243855 se my edited answer - this should help? – trainoasis Jul 24 '14 at 11:00
  • 2 Answers2

    3

    EDIT: for your purpose this would do:

    <textarea>
            Outside Textarea
            &lt;textarea&gt;Inside Textarea&lt;/textarea&gt;
    </textarea>
    

    source: How can I embed a textarea inside of another textarea in HTML?

    Or use contenteditable like someone already mentioned -> click

    FIRST ANSWER: Im not sure I understand perfectly but still. You want to display the code inside text area somewhere else for instance?

    You could do that on click like this (I reckon you are not statically putting nested text areas in html?):

    HTML:

    <textarea id="textarea" >Something code to show</textarea>
    <button onclick="show()">show</button>
    <div id="showArea"></div>
    

    JS:

    function show(){
        var t = document.getElementById('textarea').value; 
        document.getElementById('showArea').innerHTML = t;
    }
    

    This is of course if what you want is to display html that is inside textarea. you could also put another textarea inside first one and it will work.

    If you want the results to display dynamically you could use

    <textarea id="textarea" onkeyup="show()">Something code to show</textarea>
    

    This works even if you put your code (html and text area) inside text area - it displays it, I tested it

    Community
    • 1
    • 1
    trainoasis
    • 6,419
    • 12
    • 51
    • 82
    1

    You can add a output div for preview purpose. Below is the jQuery script

    HTML

    <textarea placeholder="Enter your html"><b>test</b></textarea>
     <a href="#" class="run">Run</a>
      <div class="op"></div>
    

    JS

     $('.run').click(function(){
        $('.op').html($('textarea').val());
        return false;
    });
    

    DEMO

    karan3112
    • 1,867
    • 14
    • 20