Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Tooltip function from title attribute
    primarykey
    data
    text
    <p>I have a function for creating a tooltip from a title. I am trying to wrap this function in an if statement that checks the title length before returning the tooltip. But it doesn't seem to want to return anything. Is there a better way to do this then with an if statement?</p> <pre><code>$(document).ready(function() { if ($('#menu-headermenu a').attr('title').length == 0) { return null; } else { //Select all anchor tag with rel set to tooltip $('#menu-headermenu a').mouseover(function(e) { //Grab the title attribute's value and assign it to a variable var tip = $(this).attr('title'); //Remove the title attribute's to avoid the native tooltip from the browser $(this).attr('title',''); //Append the tooltip template and its value $(this).append('&lt;div id="tooltip"&gt;&lt;p&gt;Take me to:&lt;p&gt;&lt;div class="tooltipcontent"' + tip + '&lt;/div&gt;&lt;/div&gt;'); //Set the X and Y axis of the tooltip $('#tooltip').css('top', e.pageY + 10 ); $('#tooltip').css('left', e.pageX + 20 ); //Show the tooltip with faceIn effect $('#tooltip').fadeIn('500'); $('#tooltip').fadeTo('10',0.8); }).mousemove(function(e) { //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse $('#tooltip').css('top', e.pageY + 10 ); $('#tooltip').css('left', e.pageX + 20 ); }).mouseout(function() { //Put back the title attribute's value $(this).attr('title',$('div.tooltipcontent').html()); //Remove the appended tooltip template $(this).children('div#tooltip').remove(); }); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload