I have been attempting to learn JQuery and this tutorial from a book really stumped me. I have simplified it somewhat so we are dealing with the most simple elements/functions possible. I have this table defined
<table id ="testtable">
<thead>
<th>Client Name</th>
<th>Appointment Dates</th>
</thead>
<tbody id="tabledata">
<tr>
<td>Joe</td>
<td>01/01/2012</td>
</tr>
<tr>
<td>Joe</td>
<td>01/01/2012</td>
</tr>
<[email protected]("AppointmentData", new { id = Model })-->
</tbody>
</table>
I have a button calling a function defined as
<input type="button" value="test" onclick="OnSuccess();" />
And I have my actual Jquery here
<script type="text/javascript">
function OnSuccess() {
$("#tabledata").append("<tr><td>hello</td><td>world</td></tr>");
}
</script>
What is really baffling me is the Jquery function which fails to execute. I can empty the table with .empty(), I can even perform this:
$("#tabledata").append("<td>hello</td><td>world</td>")
And it will append data but I cannot for the life of me figure out why it will not append a row. The Chrome debugger error message I get is "Uncaught TypeError: object is not a function". This only occurs when I start adding the table row tags.
Edit:
It turns out my local jQuery library was behaving oddly, maybe I modified it by accident? As soon as I referenced the google hosted library it worked
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('input[name="testButton"]').click(function () {
alert('hi');
$("#testtable tbody").append("<tr><td>hello</td><td>world</td></tr>");
});
});
</script>