Are events flaring up, yet yielding no results?

I've been following a course on Pluralsight about creating web apps using .NET Core. The instructor uses jQuery version 2.4.3, but I decided to use the latest jQuery version 3.x.

I copied the code exactly as shown in the course:

(function () {
    var ele = $("#userName");
    ele.text("Some Dude");

    var main = $("#main");
    main.on("mouseenter", function () {
        main.css("background-color", "#888;");
    });
    main.on("mouseleave", function () {
        main.css("background-color", "");
    });
})();

However, when I tried mousing over my div, nothing happened. No color change, no response at all. After some investigation, I realized that I should probably do it this way instead:

(function () {
     var ele = $("#userName");
     ele.text("Some Dude");

     var main = $("#main");
     main.on("mouseover", function () {
         console.log("enter");
         main.css("background-color", "#888;");
     })
     .on("mouseout", function () {
         console.log("out");
         main.css("background-color", "");
     });
 })();

Even though "enter" and "out" are printed in the console, the background color of my div still doesn't change.

What am I missing here?

Answer №1

To improve the code, consider removing the ";" in

main.css("background-color", "#888;")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The function **now.toUTCString** is not recognized and cannot be executed by HTMLButtonElement

While the JavaScript code runs smoothly without setting a time zone, I encountered an error when trying to display the Barbados time zone. The issue is related to now.toUTCString function throwing the following error message. How can I resolve this? Uncau ...

The body of the POST request appears to be void of any

Whenever I make a request using curl or hurl, an issue arises. Despite req.headers['content-length'] showing the correct length and req.headers['content-type'] being accurate, req.body returns as {}. Below is the Hurl test: POST http:/ ...

In Angular, what is the best way to update the quantity of an item in a Firestore database?

Whenever I attempt to modify the quantity of an item in the cart, the quantity does not update in the firestore database. Instead, the console shows an error message: TypeError: Cannot read properties of undefined (reading 'indexOf'). It seems li ...

Tips for using jQuery to send a file to the connect-busboy module in nodejs

Successfully sending a file to connect-busboy can be achieved by utilizing an HTML form's action attribute in the following manner: <form ref='uploadForm' method="post" action="http://localhost:3000/fileupload" enctype="multipart/form-da ...

How do I apply border-radius to a grid table that overflows and is scrollable?

CodePen Link I have designed a table using Grid CSS. However, I am facing an issue where I cannot apply border-radius to it due to the overflow: auto property that is necessary. Current Table Design: https://i.sstatic.net/dNehv.png Desired Table Design ...

Error message: Could not locate the class 'NunoMaduroCollisionAdaptersLaravelCollisionServiceProvider'

Encountering an error while attempting to install Composer in a Laravel project. Error message: Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover In ProviderRepository.php line 208: Class 'NunoMadur ...

Exhausting my server's capacity for HTTP requests due to heavy use of an Ajax function

I'm not very knowledgeable about servers and HTTP request limits. I currently have a Linux Deluxe hosting plan on GoDaddy, which is running smoothly. However, I am facing an issue where my website becomes unreachable (ERR_CONNECTION_CLOSED) after runn ...

Is Protractor compatible with Internet Explorer 9?

For my Angular App that is running on IE9, I need to create end-to-end acceptance tests. I'm curious to know if the browser simulated by Protractor matches the behavior of IE9 or a newer version? ...

Exploring APIs during full-stack development

When it comes to fetching APIs created on the backend, I encounter some challenges. While handling everything correctly on the front-end server side, issues arise with error handling as the catch(error) method only captures errors originating from the fron ...

Tips on accessing InnerText with VUEJS

I'm struggling with displaying the innerText generated by my generatePseudonym() function in a modal dialog. To better illustrate, here is a screenshot of what I mean: https://i.sstatic.net/pEl5P.png I am aiming to show the output Anastasia Shah as th ...

Obtain the Class Name Value by Utilizing the "Begins With" Selection Method

Consider the following HTML structure: <a href="#" class="a b nl-3522">First</a> <a href="#" class="a b nl-7352">Second</a> <a href="#" class="a b nl-4874">Third</a> <!-- Note that classes nl-* are being added dynami ...

Are you interested in learning HTML/CSS and joining a class?

When working with HTML, you can use the TOP tag to quickly navigate to the top of a page. This got me thinking - is it possible to create a link on my webpage that will take users directly to a specific class using only HTML and CSS? I'm curious to kn ...

Looking for a solution in Javascript and HTML to locate a main named window or tab and bring it to the front without loading a new URL into it

It is common knowledge that clicking <a href='a.html' target='abc'>...</a> will open a.html in a window named abc. However, if the window named abc already exists and I only want to bring it to the front without loading a.h ...

Styling a Kendo Dropdownlist with JavaScript

Incorporating Jquery Kendo Dropdownlist to showcase information in a list has been quite beneficial. My current objective is to introduce the mentioned styles (.k-list-container and .k-list-scroller) into the Dropdownlist via JavaScript. Moreover, I aim t ...

Alert: Error encountered while attempting to locate the Angular Material core theme within Angular 3, Angular Material, and Angular Material Experimental

After successfully implementing a custom color palette with Material 3 and Angular Material Experimental, I am encountering a warning in the console stating "Could not find Angular Material core theme. Most Material components may not work as expected. For ...

Can you explain the meaning behind this code snippet using spread syntax, the .map method, and .dataset.filter?

I'm currently dissecting this code snippet to understand its functionality. I am particularly puzzled by the use of spread syntax (...document.querySelectorAll) and the purpose of the .map and .dataset.filter methods. const filters = [...document.quer ...

Is it possible to allow null values for a Sequelize foreign key?

Is it possible to allow null values for a foreign key in Sequelize? The scenario involves a 'through' and 'belongsToMany' association: Shelf belongsToMany(Book, { through: Library, as: "Books"}); Book belongsToMany(Shelf, { th ...

Choosing the Right Size for Your Background Images

Struggling to adjust my body image so that it resizes based on the browser window. I have everything laid out on the page, but I want it to always fit the entire page without requiring scrolling. I attempted to use some javascript to solve the issue, but i ...

The .AppendChild() method does not appear to be working as expected following the completion of

Encountering a peculiar problem here. The scripts run smoothly, but the content doesn't display on screen until I "inspect element" and then close the inspector window or zoom in/out. It's not an issue with the "display" CSS property because even ...

Experiencing data loss while utilizing BeautifulSoup

I am currently working on a tutorial from the book 'Automate the Boring Stuff with Python' where I am practicing a project titled 'Project: “I’m Feeling Lucky” Google Search' Unfortunately, the CSS selector used in the project is ...