JSFiddle - React, Tailwind, and code Playground

by Elias Barbosa

HTML

<br /><br /><br />
<div title="This is some information for our tooltip." class="tooltip-class">
    This is a test
</div>

CSS

/* This is the CSS for the Example DIV */
div.tooltip-class {
  position: relative;
  width: 200px;
  background: red;
  padding: 10px;
  cursor: pointer;
  color: white;
  font-weight: bold;
  font-family: Arial;
}

/* This is the CSS for the actual Tool-Tip */
.tooltip-class:hover:after {
  background: #333;
  background: rgba(0,0,0,.8);
  border-radius: 5px;
  bottom: 26px;
  color: #fff;
  content: attr(tooltip-data);
  left: 20%;
  padding: 10px 15px;
  position: absolute;
  z-index: 98;
  width: 220px;
  font-size: 12px;
}

.tooltip-class:hover:before {
  border: solid;
  border-color: #333 transparent;
  border-width: 6px 6px 0 6px;
  bottom: 20px;
  content: "";
  left: 50%;
  position: absolute;
  z-index: 99;
}

JavaScript

$(document).ready(function(){
  $(".tooltip-class").hover(function(){
    $(this).attr("tooltip-data", $(this).attr("title"));
    $(this).removeAttr("title");
  }, function(){
    $(this).attr("title", $(this).attr("tooltip-data"));
    $(this).removeAttr("tooltip-data");
  });
});