Reputation: 571
I sorted through the top 12 or so questions without coming to an answer, so here's my particular state:
function someFunction( elem ){
var someVar = elem.siblings(':input[type=radio]').attr('name');
console.log( group );
}
$('my-element').on('click', $(this), someFunction );
This give me a 'Object has not method siblings' error. Originally I had the contents of somefunction inside the .on event handler as a function and things worked fine. I understand that I'm missing something with regards to how jQuery is casting $(this) about, but I'm uncertain as to what it may be. I can dump elem from inside someFunction and see the element I'm after, but I cannot manipulate it.
Any pointers?
Upvotes: 0
Views: 191
Reputation: 304
You should use bind
instead.
function someFunction(){
var someVar = $(this).siblings(':input[type=radio]').attr('name');
}
$('my-element').bind('click', someFunction);
Upvotes: 0
Reputation: 27618
function someFunction(){
var someVar = $(this).siblings(':input[type=radio]').attr('name');
console.log( group ); // <-- whats group??
}
$('my-element').on('click', someFunction);
note: my method will attach an event handler on each 'my-element'.
Upvotes: 1