How to put HTML button in the javascript code? Following is my code which creates table in in javascript code and assign it to HTML div.
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
$(document).ready(function()
{
var tablecontents = "";
tablecontents = "<table>";
for(var i=1;i<=10;i++)
{
tablecontents += "<tr>";
tablecontents += "<td>" + i + "</td>";
tablecontents += "</tr>";
}
tablecontents += "</table>";
document.getElementById("myTable").innerHTML = tablecontents;
}
});
</script>
</head>
<body>
<div id="myTable"></div>
</body>
</html>
The above code works fine and creates a table with 10 rows (one column in each row) for me. Now I wanted to create one more column in each row which would contain following button
<button type="button"
id="myButton"
onclick="myButtonClicked()"
class="myButton">Click ME
</button>
I tried like this
tablecontents += "<td>
<button type="button"
id="myButton"
onclick="myButtonClicked()"
class="myButton">Click ME
</button>
</td>";
But due to syntax error or something else, nothing was appearing on my HTML form. I think I am making some error in quotes etc.
"<td><button type='button' id='myButton'></button>"