Reputation: 10077
I'm working with the following code and I'm trying to modify the html of some table data. However, the value of $(this).html()
seems to always be undefined. I don't understand why. Could someone explain please.
$(document).on('click',"td",function() {
//console.log($(this).html());
}).focusout(function(){
console.log($(this).html()); //undifined
});
Upvotes: 1
Views: 88
Reputation: 249
try doing
$('td').on('click', function () {
}).focusout(function(){
console.log($(this).html()); //undifined
});
Your scope may be limited with your current selector.
Upvotes: 0
Reputation: 95031
You are binding an event to the document, then getting it's html. The document doesn't have html.
What you probably want is this:
$(document).on('click',"td",function() {
//console.log($(this).html());
}).on('blur','td',function(){
console.log($(this).html()); //not undifined :-)
});
Upvotes: 1