javascript - Adding a Button dynamically in a Table using HTML and Java script -


enter image description herehi 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> 

http://codepen.io/anon/pen/vlqeex


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -