putting html in title, using query

Asked

Viewed 86 times

1

Guys I have a tooltip plugin that works with jQuery, it is very simple and practical. The problem is I’m trying to put an html inside it. And it returns me the html code instead of the result. Does anyone know any way to solve this?

Follow the example below.

$(document).ready(function() {

  $('.masterTooltip').hover(function() {

    var title = $(this).attr('title');
    $(this).data('tipText', title).removeAttr('title');
    $('<p class="tooltip"></p>')
      .text(title)
      .appendTo('body')
      .fadeIn('slow');
  }, function() {

    $(this).attr('title', $(this).data('tipText'));
    $('.tooltip').remove();
  }).mousemove(function(e) {
    var mousex = e.pageX + 20; 
    var mousey = e.pageY + 10; 
    $('.tooltip')
      .css({
        top: mousey,
        left: mousex
      })
  });
});
.tooltip {
  display: none;
  position: absolute;
  border: 1px solid #333;
  background-color: #161616;
  border-radius: 5px;
  padding: 10px;
  color: #fff;
  font-size: 12px Arial;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<p><a href="#" title="tutilo com <br> html <b>aqui</b>" class="masterTooltip">coloque o mouse aqui</a>
</p>

  • You cannot use a jquery plugin with http://iamceege.github.io/tooltipster/#demos ?

1 answer

2


Exeprimente instead of:

...
$('<p class="tooltip"></p>')
  .text(title)
...

Put this:

...
$('<p class="tooltip"></p>')
  .html(title)
...

$(document).ready(function() {

  $('.masterTooltip').hover(function() {

    var title = $(this).attr('title');
    $(this).data('tipText', title).removeAttr('title');
    $('<p class="tooltip"></p>')
      .html(title)
      .appendTo('body')
      .fadeIn('slow');
  }, function() {

    $(this).attr('title', $(this).data('tipText'));
    $('.tooltip').remove();
  }).mousemove(function(e) {
    var mousex = e.pageX + 20; 
    var mousey = e.pageY + 10; 
    $('.tooltip')
      .css({
        top: mousey,
        left: mousex
      })
  });
});
.tooltip {
  display: none;
  position: absolute;
  border: 1px solid #333;
  background-color: #161616;
  border-radius: 5px;
  padding: 10px;
  color: #fff;
  font-size: 12px Arial;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<p><a href="#" title="tutilo com <br> html <b>aqui</b>" class="masterTooltip">coloque o mouse aqui</a>
</p>

  • OK thank you very much

  • You’re welcome @Hugoborges, I’m glad you solved

  • Just one more thing, is it possible to take the effect it has? type when placing the mouse, it appears in slow motion, with regulating the time of the effect, this is possible?

  • This do not know @Hugoborges, never used... But within the plugin itself should be able to regulate this

Browser other questions tagged

You are not signed in. Login or sign up in order to post.