I’m using a php loop to generate multiple button elements. How can I determine which button has been clicked by using jquery?
<script type="text/javascript">
$(function(){
if(button.click){
alert(button.id);
}
});
</script>
<?php for($x=0; $x<4; $x++){ ?>
<ul id="x">
<li><input type="button" id="<?php echo $x; ?>" value="<?php echo $x; ?>"/></li>
</ul>
<?php } ?>
The most common way to identify a element is id.
(Literally, id does mean "identification")The way you want it, should be something like this.
However, generalizing the bind to all the input elements might be a bad idea. So try giving a common class to specific elements and use
$(".yourclass")instead.