Why does this JavaScript not work?
I'm using the qTip 1.0.0-rc3 plugin for jQuery. And, although it's not a big deal, I am curious as to why this works:
$(document).ready(function() {
if (jQuery().qtip) {
$('[data-qtip]').each(function() {
var qTipConten开发者_开发知识库t = $(this).attr("data-qtip");
$(this).qtip({ content: qTipContent });
});
}
});
and this does not work:
$(document).ready(function() {
addToolTips();
});
function addToolTips() {
if (jQuery().qtip) {
$('[data-qtip]').each(function() {
var qTipContent = $(this).attr("data-qtip");
$(this).qtip({ content: qTipContent });
});
}
};
The former is being invoked within a function and the latter is not. Here is the error message from Firebug:
f(this).data("qtip") is null
I'm sure it's something stupid, but what am I missing?
Thanks.
The code you have given, is it executed in the "global scope" or is it wrapped by { and } (in another function or something)?
Wow, I feel stupid. I just found there was a hidden conflict in another one of my local files. I knew everything looked right! Thanks for the help.
Try passing this
to the addToolTips() as a parameter.
精彩评论