how to .call() on the unnamed function in javascript?

Posted by Anonymous on Stack Overflow See other posts from Stack Overflow or by Anonymous
Published on 2012-09-02T15:35:36Z Indexed on 2012/09/02 15:37 UTC
Read the original article Hit count: 198

Filed under:
|
|

Let's suppose I have button #click,

And suppose I bind the on click event as follows:

$('#click').click(function(){
   alert('own you'+'whatever'+$(this).attr('href'));
});

But I want this to refer to some other element, let's say #ahref.

If it was a named function I would simply refer it by name:

foo.call('#ahref');

How could I use .call() though, if the function is called inline and does not have a name?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery