简体   繁体   中英

Append tag to textarea as a text

I have a text area , now I want to append "<if></if>" as text each time I click some button , the problem is that when I use:

$("text area").append("<if></if>")

It is Appended as a child node , and not as text , any idea how can I make this ?? please put in mind that I want texts to be added so I cant use text() or html() , and don't want to create new div each time inside the text area.

You need to modify the "value" property:

$('#yourTextarea').val($('#yourTextarea').val() + "<if></if>");

Though the initial value for a <textarea> comes from the content between the start and end tags, you subsequently manipulate the element via the "value" property.

edit — sorry the property name is indeed "value" but you mess with it via jQuery's .val() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM