3

I am using HINT.css and would like to have the tip hide when the div/class is clicked and turned on when the use mouses out of the div/class. I thought what I have here was pretty straight forward. I am surprised it didn't work, what am I missing?

<div class="promo">
   <div class="offer hint--top hint--info hint--rounded hint--info" 
    data-hint="PUT SOME COOL COPY, TO GET PEOPLE TO CLICK!!!"></div>
</div>

$(document).ready(function() {
   $( '.promo' ).on('click','.offer', function(){
   $(this).hide();
});
   $( '.promo' ).on('mouseleave','.offer', function(){
   $(this).show();
});
}); //end of document ready
andyb
  • 43,435
  • 12
  • 121
  • 150
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141

3 Answers3

2

The problem you have is created by the way in which the HINT.css library is working. The tooltips are pseudo-elements, so although the jQuery click event added will hide the element, it will immediately appear again due to the HINT.css code :hover class which is still applying to the element.

But we can workaround this and add in the functionality by adding a display:none rule to the pseudo-element as a class which is added or removed by jQuery.

For example:

JavaScript

$(function() {
  $('.promo').on('click','.offer', function() {
    $(this).addClass('fakeHide');
  });

  $('.promo').on('mouseleave','.offer', function(){
    $(this).removeClass('fakeHide');
  });
});

CSS

.fakeHide[data-hint]:before, .fakeHide[data-hint]:after {
  display:none;
}

HTML

<div class="promo"><span class="offer hint--bottom hint--rounded hint--info" data-hint="PUT SOME COOL COPY!!">I am a promotion - hover over me</span></div>

This was a difficult one to demo. For some reason both jsFiddle and jsBin do not show the tooltips in edit mode, however they do work in live preview mode.

See demo or edit demo - and remember it only appears in live preview mode!

andyb
  • 43,435
  • 12
  • 121
  • 150
1

As soon as you click on div it hide the div but same time it firing mouseleave on div where you again calling show. that why it never will be hidden.

JSFIDDLE

Anoop
  • 23,044
  • 10
  • 62
  • 76
0

The Code which you have mentioned above does exactly what you want..

[http://jsfiddle.net/MjFRe/][1]

[1]: JsFiddle Demo

insomiac
  • 5,648
  • 8
  • 45
  • 73