I have A function in jquery which goes to a php file, which querys a database returns the results in a table with a button in each row, how do i access the buttons in the page that the jquery is on. here is some code
//function to get table form php file with button on each row
function show(str)
{
$.post('INCLUDES/gettable.php',{club: str},
function(output)
{
$('#box').html(output).show();
});
}
//when button from table is clicked do something
$("button").click(function()
{
alert("hello");
}
Any help is appreciated
Use live() or better on() (comes with latest version of jQuery) for dynamically generated html/data:
ReplyDelete$("button").on('click', function()
{
alert("hello");
}
Or
$("button").live('click', function()
{
alert("hello");
}
It looks like you're loading the tables rows in dynamically, so they won't be part of the dom at page load.
ReplyDeleteyou should use the .on() function to get access to these - see jQuery API docs