I am very new to jQuery. Below is part of my code
<div class = 'buttons'>
<span>
<input type='button' value='BUTTON1' id='button1'>
</span>
<span>
<input type='button' value='BUTTON2' id='button2'>
</span>
</div>
Using jquery, I would like to print the id of the button clicked. I tried the following:
$(".buttons > span").click(function () {
alert("YOU CLICKED" + this.id);
});
But I think this is referring to the span object. This is weird because how come the span object has a click event? Or all jquery objects have “click”?
How do I get the id of the button in the span?
Thank You.
What about this?