Total beginner question about jQuery:
I have a Form that contains several TextBoxes (input type="text"). I would like to display some sort of Tooltip when the TextBox receives focus and hide it when it loses focus. Ideally, the tooltip should be a "speech" bubble on the left or right side.
I googled a bit and found qTip for jQuery, but that seems to be a Plugin for Tooltips when hovering over something, but has the layout and positioning that I want.
My naive attempt to bind it to a textbox:
$(function() {
$("input[id$=tbMyTextbox]").qtip({
content: 'My Tooltip Text'
});
});
(The selector works, i'm not using #tbMyTextbox since it's ASP.net, and I am not using <%= tbMyTextBox.ClientID %> because I cannot have any code in my .aspx file, but that's off-topic - the selector itself works with other stuff, so I assume it's fine.).
Can anyone give me a hint how it could work or tell me about a different jQuery plugin that does that?
Thanks!
Edit: Thanks, the Show Event does the trick!
$("input[id$=tbMyTextbox]").qtip({
content: 'Test',
position: {
corner: {
target: 'rightMiddle',
tooltip: 'leftMiddle'
}
},
show: {
when: {
event: 'focus'
}
},
hide: {
when: {
event: 'blur'
}
}
});
The tooltip widget can shown via keyboard focus or by the onmouse event. The tooltip widget can be hidden by removing focus from the text box or by moving the mouse off the textbox. The tooltip widget can be hidden by pressing the Escape key. The tooltip is only hidden via JavaScript and CSS selectors.
Tooltips can be attached to any element. To display tooltips, just add title attribute to input elements and title attribute value will be used as tooltip. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element.
Tooltips are used with the element to display a title in the title box next to the element, when you hover the element with your mouse. Tooltips can be attached to any element. If you want to display tooltip, just add title attribute to input elements and the title attribute value will be used as tooltip.
The tooltip, also known as infotip or hint, is a common graphical user interface (GUI) element in which, when hovering over a screen element or component, a text box displays information about that element, such as a description of a button's function, what an abbreviation stands for, or the exact absolute time stamp ...
You could create your tooltip manually in an element hidden with display:none
which would be shown in a focus event handler.
$("input[id$=tbMyTextbox]").focus(function() {
$("div[id$=tooltip]").show();
});
$("input[id$=tbMyTextbox]").blur(function() {
$("div[id$=tooltip]").hide();
});
Another possibility might be using the show option in qTip. I've never used qTip, so this is purely theoretical on my end, but you should be able to specify show: { when: { event: 'focus' } }
in the options.
http://craigsworks.com/projects/qtip/docs/reference/#show
$(function() {
$("input[id$=tbMyTextbox]").qtip({
content: 'My Tooltip Text',
show: 'focus',
hide: 'blur'
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With