简体   繁体   中英

Jquery input ID from Class

I have:

<div class="buttons">   

<input id = "previous" class="previous_button" type="submit" 
style="margin-right: 10px;" value="Previous"/>

<input id = "next" class="next_button" type="submit" 
style="margin-right: 10px;" value="Next"/>

</div>

How can I get the id of the clicked button when I have the following code:

$(".buttons").click(function(){
        //alert("Clicked!");
        //alert($('.buttons').closest('form').attr('id'));


     })

Event delegation

$('.buttons').on('click', 'input[type=submit]', function(e) {
    alert(this.id);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM