0

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?

2
  • Looking at the docs may be beneficial. api.jquery.com/on Commented Nov 29, 2012 at 15:11
  • The jQuery docs were my first stop, but thank you for the suggestion. Commented Nov 29, 2012 at 15:29

2 Answers 2

1
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'.

Sign up to request clarification or add additional context in comments.

1 Comment

This was it, thank you. I had read in the doc that jQuery passes a data object along to the event handler, though thought there was more I had to do from there. This works, thank you.
0

You should use bind instead.

function someFunction(){
    var someVar = $(this).siblings(':input[type=radio]').attr('name');

}

$('my-element').bind('click', someFunction);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.