How would you append a
tag on a value inside a textarea, it only appends it after a keypress of SHIFT+ENTER,
here is my code to append on the text area and it does not work??
$('#textarea').append("<br/>");
i think there are still something lacking.
Thank you. . .
Are you actually wanting to place the characters in the value?
$("textarea").val(function(i,v){
return v + "<br/>";
});
Or simply add a new line?
$("textarea").val(function(i,v){
return v + "\nfoo";
});
Fiddle: http://jsfiddle.net/jonathansampson/SNeyy/
If you want to respond only to shift + enter :
$("textarea").on("keypress", function(e){
if ( e.which === 13 && e.shiftKey ) {
$(this).val(function(i,v){
return v + "<br/>"; // or return v + "\n"; (whatever you want)
});
}
});
You are trying to change the value of the textarea
. To add the string "<br/>" you have to use
$('#textarea').val($('#textarea').val() + '<br/>');
and to add a new line you have to use
$('#textarea').val($('#textarea').val() + "\n");
Textarea can have only a text node as its child. <textarea><br/></textarea>
is incorrect usage. If you want to add the string "<br/>", the html code should be
<textarea><br/></textarea>
and to add a new line, the html code should be
<textarea>
</textarea>
In other words, you cannot use <textarea><br/></textarea>
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.