I am adding content [buttons & tables] to my 'container' uses the load method.
However, dynamic content requires delegation and I believe my code for this is wrong and I am somehow confusing parents/children. When I load my page, my 'table' is loaded, without even clicking on button1.
$(document).ready(function () {
$("#button1").click(loadUserNameTable);
$("#contentbox").on("click", '#table .button2', loadQuestions);
});
function loadUserNameTable() {
$("#contentholder").load("nametable.html");
}
function loadQuestions() {
$("#contentholder").load("questions.html");
}
function loadPasswordChanger() {
$("#contentholder").load("passwordchange.html");
}
</script>
<div id="contentholder">
<button type = "button" id="button1">Begin Password Reset</button>
</div>
//nametable.html
<div class="table">
<table id="table1" style="margin:0 auto">
<tr>
<td>
Enter Username:
</td>
<td>
<input type="text" id="userName" value="" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<button id="button2" style="float: left"> Submit </button>
</td>
</tr>
</table>
</div>
//questions.html
<div class="qs" id="questions" style="margin: 0 auto">
<table style="margin: 0 auto">
<tr>
<td>Question 1: </td>
<td><input type="text" /></td>
</tr>
<tr>
<td>Question 2: </td>
<td><input type="text" /></td>
</tr>
<tr>
<td>
</td>
<td>
<button id="button2" style="float: left"> Submit </button>
</td>
</tr>
</table>
</div>