Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My JQuery show() works in IE but not FF?

In my .Net web app, I have some elements with a class of "skmTooltipHost" which are dynamically placed on a page.

When the mouse is hovered over them, a tool-tip kind of popup should display. This is working perfectly in IE, but not at all in Firefox.

Please help!

The javascript which does the "On Hover and Show"

$(document).ready(function () {
  $(".skmTooltipHost").hover(function () {
      $(this).empty().append('<div class="skmTooltipContainer"><strong>hello</strong>' + $(this).attr('tooltip') + '</div>');
      $(this).find('.skmTooltipContainer').css("left", $(this).position().left + 20);
      $(this).find('.skmTooltipContainer').css("top", $(this).position().top + $(this).height());
      $(".skmTooltipContainer").css("display", "inline-block");
      $(".skmTooltipContainer").show();
      $(this).show();
   },function () {    
     $(".skmTooltipContainer").fadeTo(500, 1.0, function () { $(this).remove(); });
   });
});

My CSS

.skmTooltipHost
{
cursor: help;
border-bottom: dotted 1px brown;

}

.skmTooltipContainer
{
padding-left: 10px;
padding-right: 10px;
padding-top: 3px;
padding-bottom: 3px;
 display:inline-block;
position: absolute!important;
background-color: #ff9;
border: solid 1px #333;
z-index: 999;
}

Edit

I finally used a set of different but similar code which does work. I'm not sure what the difference is. My working code is below:

 function simple_tooltip(target_items, name) {
      $(target_items).each(function (i) {
          $("body").append("<div class='" + name + "' id='" + name + i + "'><p>Click for a link to the run details</br><strong>Server:   </strong>" + $(this).attr('title') + "</br><strong>Information:</strong>" + $(this).attr('error') + "</p></div>");
          var my_tooltip = $("#" + name + i);

          $(this).removeAttr("title").mouseover(function () {
              my_tooltip.css({ opacity: 0.8, display: "none" }).fadeIn(100);
          }).mousemove(function (kmouse) {
              my_tooltip.css({ left: kmouse.pageX + 15, top: kmouse.pageY + 15 });
          }).mouseout(function () {
              my_tooltip.fadeOut(100);
          });
      });
  }
  $(document).ready(function () {
      simple_tooltip($(".skmTooltipHost"), "tooltip");
  });



.tooltip{
position:absolute;
z-index:999;
left:-9999px;
background-color:#dedede;
padding:2px;
border:1px solid #fff;
width:250px;

}

.tooltip p{
    margin:0;
    padding:0;
    color:black;
    background-color:white;
    padding:2px 7px;
}
like image 798
mplace Avatar asked Nov 03 '22 02:11

mplace


2 Answers

Is this (jsfiddle) the CSS/HTML/JS you’re using? This works for me in Chrome and Firefox. This line probably doesn’t do what you want though:

$(".skmTooltipContainer").fadeTo(500, 1.0, function () { $(this).remove(); });
like image 142
moeffju Avatar answered Nov 15 '22 07:11

moeffju


The problem as I see it is in those lines :

This line marks the span for removal from the DOM. Thus it disappear and you dont hover the control anymore.

$(this).empty().append('<div class="skmTooltipContainer"><strong>hello</strong>' + $(this).attr('tooltip') + '</div>');

This line removes a control from the DOM. You would think this refers to the tooltip, but in fact, it refers to the top SPAN (or tooltip host in your case).

$(".skmTooltipContainer").fadeTo(500, 1.0, function () { $(this).remove(); });

This code proved to work :

$(document).ready(function () {
  $(".skmTooltipHost").hover(function () {
      $(this).append('<div class="skmTooltipContainer"><strong>hello</strong>' + $(this).attr('tooltip') + '</div>');
      $(this).find('.skmTooltipContainer').css("left", $(this).position().left + 20);
      $(this).find('.skmTooltipContainer').css("top", $(this).position().top + $(this).height());
      $(".skmTooltipContainer").css("display", "inline-block");
      $(".skmTooltipContainer").show();
      $(this).show();
   },function () {    
     $(".skmTooltipContainer").fadeTo(500, 1.0, function () { $(".skmTooltipContainer").remove(); });
   });
});

You can test it here : http://jsfiddle.net/ab4ML/2/

Mention to moeffju for providing the fiddle.

like image 34
Yan Brunet Avatar answered Nov 15 '22 07:11

Yan Brunet