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 function
s, 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
Post a Comment