Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

jQuery - mouse enter and mouse leave events example

0 contributions
2 points

Using jQuery it is possible to create mouse enter (mouseenter) and mouse leave (mouseleave) events in following ways.

1. mouseenter and mouseleave methods example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <div id="element" style="padding: 10px; background: orange;">
    Move mouse over element...
  </div>
  <script>

    $(document).ready(function() {
		var element = $('#element');
      
      	element.mouseenter(function() {
        	element.text('Mose over element...');
        });
      
      	element.mouseleave(function() {
        	element.text('Mose left element...');
        });
    });

  </script>
</body>
</html>

2. on method with event name example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <div id="element" style="padding: 10px; background: orange;">
    Move mouse over element...
  </div>
  <script>

    $(document).ready(function() {
		var element = $('#element');
      
      	element.on('mouseenter', function() {
        	element.text('Mose over element...');
        });
      
      	element.on('mouseleave', function() {
        	element.text('Mose left element...');
        });
    });

  </script>
</body>
</html>

3. on method with event object example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <div id="element" style="padding: 10px; background: orange;">
    Move mouse over element...
  </div>
  <script>

    $(document).ready(function() {
		var element = $('#element');
      
      	element.on({
            'mouseenter': function() {
        	    element.text('Mose over element...');
            },
          	'mouseleave': function() {
                element.text('Mose left element...');
            }
        });
    });

  </script>
</body>
</html>
0 contributions

Suggested wiki articles:

Suggested findings

Let's do the work and have some fun
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way. ❤ 💻 🙂
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    we will help you. 👍 ✔ 🦄
Read more