No Added tag in textarea

I'm using the below jQuery code to add a HTML tag inside a textarea.

The problem is when the button is clicked tag is added to the textarea but when the text is written and click on the button does not work and is not text.

$(".h4").click(function(){
    $('#Article').focus();
    var h4 = "<h4></h4>";
    $("#Article").append(h4);
});

Answers 1

  • The child nodes of a textarea element only set its default value.

    If you want to change the current value, you have to access its value property (via the val() method if you are using jQuery).

    $("#Article").val(
        $("#Article").val() + h4
    );
    

Related Articles