Javascript – Jquery : how to use tooltip with JQuery

javascriptjqueryjquery-pluginsjquery-ui

I have a simple tooltip which has long JavaScript code in the divs.

I would to make it is as simple way

could any one help please

here is my code

  <div onmouseover="document.getElementById('tt1DX1').style.display='block'" onmouseout="document.getElementById('tt1DX1').style.display='none'" style="position:relative;">Tool
    <div id="tt1DX1" class="toolTip_new pbc11_ttpos1_1Q_di" style="display: none;">
      <div class="tool_wrapper">
        <div class="tooltip_top_new"></div>
        <div class="tooltip_middle_new">
          <div class="content">
            <p>Please holder actuall text</p>
            <p>Please holder actuall text</p>
            </div>
          </div>
        <div class="tooltip_bot_new2"></div>
        </div>
      </div>
    </div>

css

.tooltip_top_new{
    background:url(../images/n_tooltip_top.png) no-repeat;
    height:9px;
    width:212px;
}
.tooltip_middle_new{
    background:url(../images/n_tooltip_middle.png) no-repeat;
    width:212px;
}
.tooltip_middle_new .content{
    padding:2px 13px 1px;
}
.tooltip_middle_new .content p{
    line-height: 1.3;
    margin-bottom: 1em;
    text-align: left;
}
.tooltip_bot_new2{
    background:url(../images/n_tooltip_bot2.png) no-repeat;
    height:21px;
    width:212px;
}



.Question_di{
    position:relative;
}
.pbc11_ttpos1_1Q_di {
    border: 0 solid #FF0000;
}
.toolTip_new {
    background: none repeat scroll 0 0 transparent;
    color: #5C5C5C;
    display: none;
    font: 10px/12px Tahoma,Geneva,sans-serif;
    left: -173px;
    top: -90px;
    position: absolute;

    z-index: 1000;
}

the thing is that I have to copy & paste onmouseover="document.getElementById('tt1DX1').style.display='block'" onmouseout="document.getElementById('tt1DX1').style.display='none'" where ever using the tooltips,I would like to avoid it.

Best Solution

JQueryTools includes a Tooltip module which will get rid of a big chunk of your code.

http://jquerytools.org/demos/tooltip/index.html

It's also possible to create tooltips with no JavaScript at all, using HTML and CSS along these lines:

<div class="has-tooltip">
  <button class="huge red">You Know You Wanna...</button>
  <div class="tooltip">Do NOT Press This Button.</div>
</div>

And in CSS:

.has-tooltip .tooltip {
  position: absolute;
  display: none;

  <style code to position (with margin-left and margin-top)
   and make the tooltip box look how you want>

}

.has-tooltip:hover .tooltip {
   display: block;
 }

Google "CSS Tooltips" to see lots of examples.