I have some PHP code which generates a number of items, its not a list per se, but we can think of it as such.
For each item, I have PHP generate a button.
I need jquery to be able to register the clicking of any one of those buttons, and then to do code and grab values based on the line item that was clicked.
So I might have code like this (in my loop statement)
<br>There is a duel being held on turn $eventturn between $name1 of house $fname1 and $name2 of house $fname2! <input type=\"button\" id=\"sendsomeone\" value=\"Send a family member to spectate\"/>"
and jquery code like this
$('#sendsomeone').click(function() {
alert("button was clicked.");
});
As I’m sure you can guess, this only really works for one item, not multiple items.
How I can have jquery register different button clicks, and grab data for them?
$('input:button').click(function() {...});will put the same click handler on all the buttons at once.The click handler can then grab text stored in some attribute of the button; you can change this attribute’s value for each button without affecting the HTML render. For instance:
And this script:
Will pop up “whatsit” when the first button is clicked and “ooga” when the second is clicked.