Saturday, 14 September 2013

why is myvar undefined after myvar = $(this)

why is myvar undefined after myvar = $(this)

So I am making a little game about a survivor in a desert. The survivor
has to drink from wells scattered throughout the desert on his way back to
Gold Rush Ghost Town. Some wells are good to drink from but others are
poisoned. I am displaying a tooltip on those TD elements of a table that
have the class "well". Inside the tooltip's initialization object, I need
to get a reference to the current TD element, so I can pass it to a
function that sets the tooltip's "content" property. Inside that function
I must test if the current TD has the class "poisoned" too.
function initWellsTooltip() {
$("#water-table tbody td.well").tooltip({
content: function () {
var well$ = $( this ); //
// at this point stepping through the code in the debugger,
// well$ is undefined and I don't understand why,
// because $(this).hasClass("poisoned") succeeds.
// VS2010 debugger shows as follows:
// ?$(this).hasClass("poisoned")
// true
// ?well$
// 'well$' is undefined
if (well$.hasClass("poisoned")) {
return "poisoned!";
} else {
return "potable";
}
},
items: "td.well",
position: { my: "left+15 center", at: "left top" }
});
}

No comments:

Post a Comment