<input type="button" id="addButton1" class="myButton" /> <input type="button" id="addButton2" class="myButton" />
<script type="text/javascript"> $(document).ready(function() { $('.myButton').click(function() { alert($(this).attr('id')); // alert(this.id) <-- should also work } }); </script> Notice that I added a class="myButton" to each button element, and set the listener for $('.myButton').click(), which listens for a click event on any element that matches that selector. Within the function triggered by the click event, $(this) or this are both references to the element that triggered the click. On Tue, Jan 5, 2010 at 12:35 PM, CoffeeAddict <dschin...@gmail.com> wrote: > > I understand that I can use the .click() method on a hyperlink element. > But > how do I know which element was clicked? First I have to gain reference to > the hyperlink's ID. > > So lets say I have a page of hyperlinks like this in view source: > > ...someurl somebutton > ...someurl somebutton > ...someurl somebutton > ...someurl somebutton > > when a user clicks addButton1, how do I know it's addButton1 that was > referenced so that I can now apply a .click() event on it? > -- > View this message in context: > http://old.nabble.com/How-to-gain-reference-to-hyperlink-that-is-clicked-tp27026713s27240p27026713.html > Sent from the jQuery General Discussion mailing list archive at Nabble.com. > > -- Charlie Griefer http://charlie.griefer.com/ I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success.