JavaScript/jQuery: How do you pass an element to a function as its 'this'? -


how pass function, if calls function?

say have function

function showid() {   alert($(this).attr('id')); } 

and html

<div id='div1'>   <a class='link'>some link</a> </div> 

i want this

$('div .link').click(function() {   $(this).parent('div').call(showid); // right syntax? }); 

and should alert: div1

.call() method of functions, order other way around:

showid.call($(this).parent('div')); 

though, passing argument viable:

function showid(elem) {     alert($(elem).attr('id')); } 
showid($(this).parent('div')); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -