Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jqurey append html as text to textarea

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #38994
    Al3ks
    Participant

    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

    #106506
    Taufik Nurrohman
    Participant
    $(function() {
    $('#answer2').click(function() {
    var content = '✓ TADAAA!';
    $('textarea').append(
    content
    .replace(/&/g, '&')
    .replace(/ .replace(/>/g, '>')
    );
    });
    });

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

    #106600
    Al3ks
    Participant

    @Hompimpa Thank you!! worked perfectly.

    #106601
    Al3ks
    Participant

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

    #106615
    Vermaas
    Participant

    Try this:


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

    instead of this:


    $('#answer2').click(function(){});
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.