Reputation: 445
I've had no problems getting my .click handlers to fire elsewhere on my page. For some reason, I can't seem to figure out why my handler isn't firing for a jQuery button .click event. I've trawled through so many other questions posted here, but I haven't had any luck.
The first part of the code gets the button element and calls the .click function on it. I've also changed the text of the button to prove that I'm selecting the right element.
var removeButton = $("friend_remove_button");
removeButton.text("remove");
removeButton.click( function(eventObject)
{
removeFriendFromList(eventObject);
});
The second part of the code is the removeFriendFromList function. This has more stuff happening in my project, but I can't even get it to display an alert, as seen here. Once I can get that going, I should have not problem.
function removeFriendFromList(eventObject)
{
alert("Button Clicked!");
selectedId = $(eventObject.currentTarget).attr('id');
}
You can find a jsFiddle of my code here: http://jsfiddle.net/YLNkE/1/
Any idea what I'm doing wrong? Thanks in advance!
Upvotes: 0
Views: 99
Reputation: 17366
You should look at the class selectors in jQuery/CSS
var removeButton = $(".friend_remove_button");
Note:
.
is for class selectors and #
is for Id selector and for standadard HTML controls take names directly like input
, button
, select
.. etc. not custom buttons.
Upvotes: 0
Reputation: 4435
var removeButton = $(".friend_remove_button");
You are missing the .
in your selector.
Upvotes: 3