I'm trying to advance the Jquery-autcomplete function. I want Jquery-autocomplete to create new rows in a table. That works so far. But I want Jquery to add a delete-button. So the user is able to delete one of his added items.
$(document).ready(
function() {
//create an new <tr> <td> in #log
function log( message ) {
$("<tr> <td>" + message + "<input class='Entf' type='button' value ='Entfernen' />" + "</td></tr>").appendTo("#log");
$( "#log" ).attr( "scrollTop", 0 );}
// get the values from a json-source
$( "#REMOTE" ).autocomplete({
source: "json.php",
minLength: 0,
select: function( event, ui ) {
log( ui.item ?
ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );}
});
// this is just a test if jquery recognizes the click
$('.Entf').click(function(event){
alert("Thanks for visiting!");
});
});
But jQuery doesen't recognize the click of the element it created. To check fpr erros, I placed one row in the html. This button works. But when I add a row via Jquery, the added button deon't work. Here an example from firebug:
<table id="log" border="0" width="400">
<tbody>
<tr>
<td>
test
<input class="Entf" type="button" value="Entfernen"> //this one workes fine. it comes from the original html
</td>
</tr>
<tr>
<td>
daniel aka 121
<input class="Entf" type="button" value="Entfernen"> //this one doesn't work. it's the one that was added by Jquery
</td>
</tr>
</tbody>
</table>
Any ideas?
Thank you! Exuse my english :)