How to show calendar on hover? [SOLVED]


Author: Steve Alila
Reviewer: Deepak Prasad

The most common ways to show calendar on hover are using JavaScript's mouseenter event and jQuery's  hover and  focus functions.

mouseenter event

const calendar = document.querySelector('<selector>')

document.querySelector('<text box selector>').addEventListener('mouseenter', function() {
    calendar.classList.add('<CSS class>')

jQuery hover and focus functions

// hover
$(document).ready( function() {
    $('<text box selector>').hover( function() {
       $('<calendar selector>').addClass('<CSS class>')

// focus
$(document).ready( function() {
    $('<text box selector>').focus( function() {
       $('<calendar selector>').addClass('<CSS class>')

This tutorial shows you how to show calendar on hover using the three methods. First, we download and customize this free calendar template


Lab environment setup

Create the project directory and open it before creating six files. I am using Ubuntu 22.04 with Visual Studio Code.

mkdir calendarOnHover && cd calendarOnHover
touch index.html style.css script.js jQueryHover.js jQueryFocus.js mouseenter.js
code .

The index.html, style.css, and script.js files originate from the calendar template. We will customize the index.html file and introduce a few designs in the style.css file to accommodate using jQuery and custom events in jQueryHover.js, jQueryFocus.js and mouseenter.js files, respectively.


<!DOCTYPE html>
<html lang="en" >
    <meta charset="UTF-8">
    <title>Show calendar on hover</title>
    <link rel="stylesheet" href="">
    <link href='/assets/vendor/googleapis/css?family=Roboto:400,900,700,500,300,100' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href=""><link rel="stylesheet" href="./style.css">

    <div class="container">
      <div class="calendar">
        <div class="front">
          <div class="current-date">
            <h1>Monday 12</h1>
            <h1>December 2022</h1>	

          <div class="current-month">
            <ul class="week-days">
            <div class="weeks">
              <div class="first">

              <div class="second">
                <span class="active">12</span>
                <span class="event">14</span>

              <div class="third">

              <div class="fourth">
                <span class="next-month">01</span>

              <div class="fifth">
                <span class="next-month">02</span>
                <span class="next-month">03</span>
                <span class="next-month">04</span>
                <span class="next-month">05</span>
                <span class="next-month">06</span>
                <span class="next-month">07</span>
                <span class="next-month">08</span>

        <div class="back">
          <input placeholder="What's the event?">
          <div class="info">
            <div class="date">
              <p class="info-date">
              Date: <span>Dec 15th, 2022</span>
              <p class="info-time">
                Time: <span>6:35 PM</span>
            <div class="address">
                Address: <span>129 W 81st St, New York, NY</span>
            <div class="observations">
                Observations: <span>Learn how to show calendar on hover</span>

          <div class="actions">
            <button class="save">
              Save <i class="ion-checkmark"></i>
            <button class="dismiss">
              Dismiss <i class="ion-android-close"></i>


      <div class="form">
        <label for="month">Month</label>
        <input type="text" id="text-box" name="month">


<!-- partial -->
  <script src=''></script>
  <script  src="./script.js"></script>

  <script src="" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
  <script src="mouseenter.js"></script>


We update the page title and details of the calendar, then add the text box section inside the container class but below the calendar class. We also import the minified jQuery CDN to work the library in the mouseenter.js file.


.container {
	margin: 0 auto;
	height: 100%;
	width: 100%;
	max-width: 600px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;

.calendar {
	background: #2b4450;
	border-radius: 4px;
	box-shadow: 0 5px 20px rgba(0, 0, 0, .3);
	height: 490px;
	perspective: 1000;
	transition: .9s;
	transform-style: preserve-3d;
	width: 100%;
	display: none;

form {
	padding: 1rem;

input {
	padding: .5rem;
	border-radius: 3px;
	border: 2px solid #dfebed;
.show-calendar {
	margin-bottom: 2rem;
	display: block;

We change the container class display and hide the calendar before styling the form and text box.

How to show calendar on hover? [SOLVED]


const app = {
	settings: {
		container: $('.calendar'),
		calendar: $('.front'),
		days: $('.weeks span'),
		form: $('.back'),
		input: $('.back input'),
		buttons: $('.back button')

	init: function() {
		instance = this
		settings = this.settings

	swap: function(currentSide, desiredSide) {


	bindUIActions: function() {
		settings.days.on('click', function(){
			instance.swap(settings.calendar, settings.form)

		settings.buttons.on('click', function(){
			instance.swap(settings.form, settings.calendar)


The script.js file achieves calendar flips and updates on the calendar details.

How to show calendar on hover? [SOLVED]

Here is how we can show the calendar on mouse hover.


How to show calendar on hover using the mouseenter event


Link the HTML file with the mouseenter.js file to use it.

const calendar = document.querySelector('.calendar')
const textBox = document.querySelector('#text-box')

textBox.addEventListener('mouseenter', () => {

We grab the calendar div with its class. Likewise, we grab the text box with its id and run a mouseenter event on it. We then show the calendar using the classList's add() function with the show-calendar class we created in the style.css file.

We can also use the remove() function to hide the shown calendar. Or use the toggle() function, which hides or shows the calendar depending on the active (hidden or shown) status.

const calendar = document.querySelector('.calendar')
const textBox = document.querySelector('#text-box')

textBox.addEventListener('mouseenter', () => {


How to show calendar on hover? [SOLVED]

After hover

show calendar on hover using mouseenter event

Apart from the mouse events, we can show calendar on hover using some libraries and their methods. For example, we can use jQuery's hover and focus functions or Bootstrap's popover function.

Here is how to use jQuery's hover and focus functions.


How to show calendar on hover using the jQuery


$(document).ready( () => {
    $('#text-box').hover( () => {

We wait for the elements to appear on the page before adding the show-calendar class to the div with the calendar class. That happens on hovering the text box.


 $(document).ready( () => {
    $('#text-box').focus( () => {

Similarly, we let jQuery wait till the target elements are fully loaded $(document).ready( () => { }). The library then listens for the mouseenter event using its focus() function $('#text-box').focus( () => {}).

Next, jQuery grabs the calendar div $('.calendar'). Then, it appends a new class to the div addClass('show-calendar') using the addClass() method.

The difference between the hover() and focus() functions is that we must click the text box for the calendar to appear when using the focus() function. On the hand, as the name suggests, the hover() function does not require a mouse click on the text box.



You can show calendar on hover using events like mouseenter. Otherwise, use a library's method like jQuery's hover and focus method or Bootstrap's popover function.




Views: 22
Steve Alila

Steve Alila

He 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, and data presentation using Matplotlib and Plotly. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment