Skip to main content

Jquery table onclick events



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


Comments

  1. Use live() or better on() (comes with latest version of jQuery) for dynamically generated html/data:

    $("button").on('click', function()
    {
    alert("hello");
    }


    Or

    $("button").live('click', function()
    {
    alert("hello");
    }

    ReplyDelete
  2. It looks like you're loading the tables rows in dynamically, so they won't be part of the dom at page load.

    you should use the .on() function to get access to these - see jQuery API docs

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?