I have a div tag as follows:
<html>
<head></head>
<body>
<div>
<label>Name</label>
<input type="text"/>
</div>
</body>
</html>
Now I want a simple javascript for displaying a tooltip on :hover the div. Can someone please help me out? The tooltip should also have a fade in/out effect.
A CSS3-only solution could be:
CSS3:
HTML5:
You could then create a
tooltip-2
div the same way... you can of course also use thetitle
attribute instead ofdata
attribute.You can use title. it'll work for just about everything
<div title="Great for making new friends through cooperation.">
<input script=JavaScript type=button title="Click for a compliment" onclick="window.alert('Your hair reminds me of a sunset across a prairie')" value="making you happy">
<table title="Great job working for those who understand the way i feel">
just think of any tag that can be visible to html window and insert a
title="whatever tooltip you'd like"
inside it's tag and you got yourself a tooltip.Here's a pure CSS 3 implementation (with optional JS)
The only thing you have to do is set an attribute on any div called "data-tooltip" and that text will be displayed next to it when you hover over it.
I've included some optional JavaScript that will cause the tooltip to be displayed near the cursor. If you don't need this feature, you can safely ignore the JavaScript portion of this fiddle.
If you don't want the fade-in on the hover state, just remove the transition properties.
It's styled like the
title
property tooltip. Here's the JSFiddle: http://jsfiddle.net/toe0hcyn/1/HTML Example:
CSS:
Optional JavaScript for mouse position-based tooltip location change:
For the basic tooltip, you want:
For a fancier javascript version, you can look into:
http://www.designer-daily.com/jquery-prototype-mootool-tooltips-12632
The above link gives you 12 options for tooltips.
Try this. You can do it with only css and I have only added
data-title
attribute for tooltip.There are lots of answers to this question but still may be it will help someone. It is for all left, right, top, bottom positions.
Here is the css:
And the HTML tag can be like this:
<p data-tooltip-position="right" data-tooltip="Some tooltip text here" title="">Text Here</p>
<p data-tooltip-position="left" data-tooltip="Some tooltip text here" title="">Text Here</p>
<p data-tooltip-position="top" data-tooltip="Some tooltip text here" title="">Text Here</p>
<p data-tooltip-position="bottom" data-tooltip="Some tooltip text here" title="">Text Here</p>