Reputation: 24729
I am getting id is undefined. http://jsfiddle.net/valamas/YUPWu/
I am hoping someone will pick up my (trivial?) error.
thanks
Upvotes: 0
Views: 62
Reputation: 35572
Its because this
is inaccessible. DEMO
$(function ()
{
$(document).on('click', "#MyId", function () { MyId_Click(this); });
});
function MyId_Click(obj)
{
var theId = $(obj).attr('id');
alert(theId);
}
Upvotes: 2
Reputation: 33661
It's because $(this) is referring to nothing? $(this) usually means your selected item.. which in your case is nothing since inside that function it's not pointing to any element. You can do it like this
$(function (){
$(document).on('click', "#MyId", function () {
var theId = $(this).prop('id'); //$(this).id does not work either.
alert(theId);
});
});
Upvotes: 3