Reputation: 1643
I am trying to insert a breakline (<br />
) after every textbox on click of a button using the below code :
HTML:
<input type="text" id="text1" /><b>This is test</b>
<br />
<button>New line</button>
Jquery:
$(document).ready(function(){
$("button").click(function(){
$("#text1").append("<br />");
});
});
I am getting the following error in the console
Message: Object doesn't support this property or method
Please let me know how I can achieve this.
Upvotes: 1
Views: 1300
Reputation: 28753
Try with this
$(document).ready(function(){
$("button").click(function(){
$("#text1").after("<br />");
});
});
Upvotes: 1
Reputation: 35973
Try this:
$(document).ready(function(){
$("button").click(function(){
var txt = $("text1");
txt.val( txt.val() + "\n");
});
});
Upvotes: 1