Show Calendar on Hover with JavaScript and jQuery

Learn how to show a calendar on hover with JavaScript mouseenter, jQuery hover, and focus examples.

Published

Updated

Read time 2 min read

Reviewed byDeepak Prasad

Show Calendar on Hover with JavaScript and jQuery

Showing a calendar on hover is a common UI pattern when you want to reveal date options without taking space on the page. The usual approach is to toggle visibility on hover, focus, or pointer entry.

You can implement it with JavaScript mouseenter or with jQuery hover() and focus(). If the next step is text cleanup around a date field, JavaScript trim is often part of the same form workflow.

Where to run these snippets: The plain JavaScript example needs a real browser (or jsdom / similar) because it uses document and addEventListener. The jQuery examples need a page that loads jQuery and markup with #date-input and .calendar. Outputs below describe browser behavior, not Node.js console text.


Show the calendar with mouseenter

mouseenter runs when the pointer enters the target field (unlike mouseover, it does not bubble from child elements).

javascript
const calendar = document.querySelector(".calendar");
const input = document.querySelector("#date-input");

input.addEventListener("mouseenter", function () {
  calendar.classList.add("open");
});

In the browser: after the pointer enters #date-input, the element .calendar gains the class open (your CSS should show the calendar when .calendar.open or similar is styled).


Show it with jQuery hover()

hover() is a direct way to attach a show action to pointer entry.

javascript
$("#date-input").hover(function () {
  $(".calendar").addClass("open");
});

In the browser: same visible result as above — calendar receives open when the pointer enters the input (jQuery must be loaded).


Show it on focus

focus is a practical fallback for keyboard users and touch devices where hover is unreliable.

javascript
$("#date-input").focus(function () {
  $(".calendar").addClass("open");
});

In the browser: when #date-input receives keyboard focus, .calendar gets the open class. Pair this with a blur or outside-click handler if you need the calendar to hide again.


Summary

To show a calendar on hover, use mouseenter in plain JavaScript, hover() in jQuery, and focus() when you also want keyboard-friendly behavior. The pattern is small, but it improves date-picker UX because the calendar stays hidden until the user needs it and remains usable on touch devices, mouse input, and keyboard navigation. That makes it a practical fit for forms that need a compact and accessible date interaction.


Official documentation

Steve Alila

Specializes in web design, WordPress development, and data analysis, with proficiency in Python, JavaScript, and data extraction tools. Additionally, he excels in web API development, AI integration, …