How do you check whether a button is clicked or not in jQuery?

Thảo Justin

New member
How do you check whether a button is clicked or not in jQuery?
Answer
jQuery(‘:button’). click(function () { if (this.id == ‘button1’) { alert(‘Button 1 was clicked’); } else if (this.id == ‘button2’) { alert(‘Button 2 was clicked’); } }); EDIT:- This will work for all buttons. $(‘input[type=”button”]’).
 

Tìm kiếm

Back
Top