I've got the following html
<input class="hasToolTip" type="text" value="meh"/>
<span class="tooltip" style="display: none;">tooltip here</span>
i'd like the tooltip to fade in when the input gets focus, so i created a namespace (it contains all my javascript for inputs/forms in the following way) with the correct method
var inputCommon = (function() {
return {
SetupToolTips: function() {
$(".hasToolTip").live('focus', function() {
开发者_运维百科 $(this).next(".tooltip").fadeIn();
});
$(".hasToolTip").live('blur', function() {
$(this).next(".tooltip").fadeOut();
});
}
};
})();
I then call it when the document is loaded
$(function() {
inputCommon.SetupToolTips();
});
And... it doesn't work with jQuery 1.3.2. It works with 1.4.2 though, but i'm really ready to push a library change at the moment.
Any idea how i can have my cake (namespace!) and eat it too (live working!)?
Not one to resist making a fool of myself, here is the explicit excerpt i had skipped, straight from the horse's mouth:
In jQuery 1.3.x only the following JavaScript events (in addition to custom events) could be bound with .live(): click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.
(...)
As of jQuery 1.4.1 even focus and blur work with live (mapping to the more appropriate, bubbling, events focusin and focusout).
You can't really, not without some serious changes that would likely introduce more issues than upgrading to 1.4+ would. The event system got a huge overhaul in 1.4.2, and further refinements since then...your time would be much better spent on upgrading to jQuery 1.4+ than trying to work support for this into 1.3.x.
You can always do it this way...
var inputCommon = (function() {
return {
SetupToolTips: function() {
$(".hasToolTip").focus(function() {
$(this).next(".tooltip").fadeIn();
});
$(".hasToolTip").blur(function() {
$(this).next(".tooltip").fadeOut();
});
}
};
})();
rather than using live.
精彩评论