I’m trying to insert some dynamically generated html (via PHP) into a table, but I’m embarrassingly horrible at using JQuery functions to traverse the DOM.
Here’s my table:
<table id = "tasks_table">
<tr>
<th>Date</th>
<th>Hours</th>
<th>Task</th>
<th></th>
</tr>
<tr id = "form">
<form action="index.php" method="POST" id="task_form">
<td><input type="text" id="deadline_text" name="deadline_text"/></td>
<td><input type="text" id="duration_text" name="duration_text"/></td>
<td><input type="text" id="description_text" name="description_text"/></td>
<td><input type="submit" value="Add Task" id="task_submit"/></button></td>
</form>
</tr>
<?php
//TaskDB::generateTaskTable();
?>
</table>
…And the code is going where the PHPcomment is–after the second row. I’ve tried using :nth-child and a few others without success. Any help would be much appreciated!
Jquery:
<script>
$(document).ready(function(){
$('#task_submit').on('click', function(e){
$.post('index.php', $("#task_form").serialize(), function(data){
$(' ').append(data);
console.log(data);
});
e.preventDefault();
});
});
</script>
Try the
afterorinsertAftermethods, which are documented with examples here, e.g.where
php_codeis the code you want to insert.