Grow your CSS skills. Land your dream job.

Jqurey append html as text to textarea

  • # July 20, 2012 at 9:32 pm

    Hi

    I am trying to make a link which once clicked will add text to the text area/field. The text needs to be pure text (HTML not translated).

    So I got two pieces of jquery code which I struggling to make work together to achieve what I want.

    To make HTML be plain text I have this code:

    var text = document.createTextNode('

    MyText

    ');
    document.body.appendChild(text);

    And to append the

    MyText

    to the text area I have a rough idea, like this:

    $("#answer1").click(function(){
    $('ul li').append('✓');
    });

    (found on internet)

    Now can anyone help me structure this code to function the way I want, please?

    Regards
    Aleksander

    # July 21, 2012 at 12:34 am
    $(function() {
    $('#answer2').click(function() {
    var content = '✓ TADAAA!';
    $('textarea').append(
    content
    .replace(/&/g, '&')
    .replace(/ .replace(/>/g, '>')
    );
    });
    });

    http://jsfiddle.net/tovic/kMmVU/3/

    # July 22, 2012 at 6:28 pm

    @Hompimpa Thank you!! worked perfectly.

    # July 22, 2012 at 6:29 pm

    ohh, but it doesn’t work once you type something in… any ideas?

    # July 23, 2012 at 4:08 am

    Try this:


    $('#answer2').live('click', function(){});

    instead of this:


    $('#answer2').click(function(){});
    # July 23, 2012 at 5:26 am

    http://jsfiddle.net/kMmVU/4/

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".