jQuery accessible simple tooltip window, using ARIA
This jQuery plugin will provide you an accessible and simple non-modal tooltip, using ARIA.
Installation
You can download and install the plugin via:
- npm:
$ npm i jquery-accessible-simple-tooltip-aria
- bower:
$ bower install jquery-accessible-simple-tooltip-aria
Demo
The demo is here: https://a11y.nicolas-hoffmann.net/simple-tooltip/
Why it is accessible
- It relies on ARIA Design pattern for Tooltips;
- Thanks to
aria-describedby
andid
s generated on the fly, you never loose any information; - You can close it using Esc.
How it works
Default
Basically, the scripts wraps each class="js-simple-tooltip"
into a span class="<your-prefix-class>-container"
and adds the content into a hidden content next to it. Once you focus or hover the element with class="js-simple-tooltip"
, it is displayed.
You can use it on the tag you want (input
, button
, a
…)
jQuery Plugin
;
License
No license problem, it uses MIT license, so it’s free, open-source and you can do whatever you want with it, including commercial use (permission notice)
Options and attributes
Use data-simpletooltip-text
or data-simpletooltip-content-id
attributes on an element to activate the tooltip.
- Simply put
class="js-simpletooltip"
on a button to activate the script. - Attribute
data-simpletooltip-prefix-class
(non mandatory): the prefix to all style classes of the tooltip (useful to set up different styles). - Attribute
data-simpletooltip-text
: the text of your tooltip. - Attribute
data-simpletooltip-content-id
: theid
of (hidden) content in your page that will be put into your tooltip. - Attribute
data-simpletooltip-wrapper-tag
: the tag used for wrapping your tooltip (span
by default). - Attribute
data-simpletooltip-tag
: the tag used for your tooltip (span
by default).
How to style it
/* it will work better with this box-sizing, you may adapt it to your needs *//*html { box-sizing: border-box; }*, *:before, *:after { box-sizing: inherit;}*/ /* Tooltip hidden by default *//* position relative for containers */ /* tooltip styles *//* used pseudo-element to make arrows */ /* it can be easily adapted in media-queries for tablets/mobile */ /* for this example: mobile */{ }
examples
Hover or focus me to show the tooltip Show me another tooltipWoot, you can take the content of a hidden block.
Enjoy.