Showing extra information when a user points to an element can be useful, but a mouse-only mouseover interaction excludes keyboard and touch users. Use an interaction that also works with focus and, where appropriate, click/tap.
For content users intentionally open and close, <details> and <summary> often provide a better native solution than manually showing a floating DIV.
const trigger = document.getElementById('helpLink');
const panel = document.getElementById('helpText');
['pointerenter', 'focus'].forEach(type =>
trigger.addEventListener(type, () => panel.hidden = false)
);
['pointerleave', 'blur'].forEach(type =>
trigger.addEventListener(type, () => panel.hidden = true)
);
The existing demonstration is preserved for comparison with the older mouse-event technique.
DIV basics DIV positioning DIV click interaction Show/hide layer
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Yaz | 25-01-2012 |
| GREAT JOB! BIG THANKS! FOR THIS IS EXTREMELY USEFULL! | |
| dipesh | 04-12-2013 |
| It's a great site to learn. I learn something new about <div> tag and it's become very useful to me. Thank you | |