JQuery : appendTo() within Form element not working -
i'm trying create page text entered user in 3 separate text-areas extracted , inserted fourth text-area generated when button clicked. @ moment i'm experimenting simple version , reason cannot generate additional text-area when 'generate' button clicked. thing puzzles me works fine if comment out <form> , </form> elements!
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><script> $(document).ready(function(){ $("#b1").on("click", function(){ $("<div><textarea>come on</textarea></div>").appendto("#why"); }); }); </script> </head> <body> <form action=""> <div id="why"> <textarea name="iwant">why.</textarea> </div> <div id="what"> <textarea name="iwant">what.</textarea> </div> <div> <button id="b1" type="submit">generate</button> </div> </form> </body> </html>
use event.preventdefault() in context. prevents default action otherwise page should redirected
$("#b1").on("click", function(event){ event.preventdefault(); $("<div><textarea>come on</textarea></div>").appendto("#why"); });
Comments
Post a Comment