javascript - Adding a Button dynamically in a Table using HTML and Java script -
hi have table, have add button, beside +, when ever click on it.
the code not working. not understand why.
function addproject() { var r = $('<input/>').attr({ type: "button", id: "field", value: 'project' }); $("#idproject").parent().append(r); }
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <thead> </thead> <tbody> <tr> <td style="text-align:center; width:8%"></td> <td style="text-align:center; width:8%"><input id="idproject" type="button" style="border:1px solid grey;text-align:center;background-color:#e0eeee" value="+" onclick=addproject() /></td> </tr> </tbody> </table> </html>
use following code view demo
<!doctype html> <html> <body> <p>click button make button element text.</p> <button onclick="createbtn()">create</button> <script> function createbtn() { var btn = document.createelement("button"); var t = document.createtextnode("click me"); btn.appendchild(t); document.body.appendchild(btn); } </script> </body> </html>
Comments
Post a Comment