Friday, 29 May 2009

JS: Display tooltip over page element

To display a tooltip over a page element:
  1. Create hidden tooltip element:
  2. Create JS scripts for showing/hiding tooltip:
    function show()
    {
    var tooltip = document.getElementById('tooltip');
    tooltip.style.top = event.clientY;
    tooltip.style.left = event.clientX + 10;
    tooltip.style.display = 'block';
    }

    function hide(){
    var tooltip = document.getElementById('tooltip');
    tooltip.style.display = 'none';
    }
  3. Set Javascript events for the chosen page element:

    Element content
Tested on IE7.

No comments: