Last post Aug 06, 2020 07:28 PM by cenk1536
Member
527 Points
2728 Posts
Aug 06, 2020 06:26 PM|cenk1536|LINK
Hi,
I would like to append text after clearing the text area. How can I achieve it?
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("#result").append("Test"); }); $("#btn2").click(function(){ $("#result").val(''); }); }); </script> </head> <body> <textarea class="form-control" id="result" rows="5" readonly></textarea> <button id="btn1">Append text</button> <button id="btn2">clear</button> </body> </html>
All-Star
53641 Points
24001 Posts
Aug 06, 2020 07:14 PM|mgebhard|LINK
cenk1536 I would like to append text after clearing the text area. How can I achieve it?
It really helps to read the official jQuery reference docs. The jQuery append() function modifies the DOM. The val() function gets/sets an input's value.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function () { var val = $("#result").val() $("#result").val(val + "World"); }); $("#btn2").click(function(){ $("#result").val(''); }); }); </script> </head> <body> <textarea class="form-control" id="result" rows="5" readonly>Hello </textarea> <button id="btn1">Append text</button> <button id="btn2">clear</button> </body> </html>
Aug 06, 2020 07:28 PM|cenk1536|LINK
thank you.
Member
527 Points
2728 Posts
jquery append
Aug 06, 2020 06:26 PM|cenk1536|LINK
Hi,
I would like to append text after clearing the text area. How can I achieve it?
All-Star
53641 Points
24001 Posts
Re: jquery append
Aug 06, 2020 07:14 PM|mgebhard|LINK
It really helps to read the official jQuery reference docs. The jQuery append() function modifies the DOM. The val() function gets/sets an input's value.
Member
527 Points
2728 Posts
Re: jquery append
Aug 06, 2020 07:28 PM|cenk1536|LINK
thank you.