Languages
[Edit]
EN

JavaScript - show text on hover

6 points
Created by:
Palpys
764

In this article, we would like to show you how to show text on hover using JavaScript.

Practical example:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    span.element {
        background: #28a745;
        color: white;
    }

    span.text {
        background: #bebebe;
        color: black;
    }

  </style>
</head>
<body>
  <span id="element" class="element">Hover me!</span>
  <span id="text" class="text" style="display: none">Example text...</span>
  <script>
    
      var element = document.querySelector('#element');
      var text = document.querySelector('#text');
    
      element.addEventListener('mouseover', function() {
          text.style.display = '';
      });
      element.addEventListener('mouseout', function() {
          text.style.display = 'none';
      });
    
  </script>
</body>
</html>

 

See also

  1. CSS - show text on hover

Alternative titles

  1. JavaScript - show text on parent element hover
  2. JavaScript - reveal text on parent element hover
  3. JavaScript - text show up on parent element hover
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join