It appears that jQuery is interfering with the CSS webkit hover effect and causing it

I've implemented multiple divs with the class .note and applied the following CSS code to them:

    .note{
            background: #eff9ff;
            -webkit-transition: background .5s;
        }

            .note:hover{
                background: #d6e4f2;
            }

            .note:active{
                background: #bfcdda;
            } 

The webkit animation smoothly changes colors on hover over the div.

In addition, I'm using jQuery to completely alter the background of the div based on the attribute 'selectednote' after it's clicked, reverting back when clicked again. Here's my jQuery script:

$('.note').click(function(){
if($(this).attr('selectednote')=='no'){
    $(this).attr('selectednote','yes');
    $(this).css('background','#bfcdda');
}else if($(this).attr('selectednote')=='yes'){
    $(this).attr('selectednote','no');
    $(this).css('background','#eff9ff');
}
});

Although everything works as intended, once the div's background has been changed upon clicking, the CSS hover and active effects cease to function.

I've considered eliminating the CSS for those effects entirely. I attempted implementing a jQuery solution for the hovering effect, but encountered difficulties. Here's what I tried:

$('.note').mouseover(function(){
$(this).animate({
    background: '#d6e4f2'
},500);
});

What am I missing or doing incorrectly in this situation?

Answer №1

After including !important in the :hover declaration, the issue appears to be resolved.

.note:hover{
    background: #d6e4f2 !important;
}

Check out the demo here

Answer №2

Utilize CSS to achieve this effect without resorting to using unauthorized custom attributes.

.note.selected {
  background: #bfcdda;
}​

This involves a basic toggle of the selected class. You also have the option to make adjustments utilizing .data().

$('.note').click(function(){
  $(this).toggleClass("selected");
});​

View it in action here.

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

How to align an element to the right when dealing with text overflow

Align text to the right when it overflows its parent element. https://i.sstatic.net/nTRjc.png Check out my code example here: https://stackblitz.com/edit/react-jjno6n ...

What is the best way to place tfoot at the top of the table

Below is the structure of my table: https://i.stack.imgur.com/QmlVn.png In the table, there are search input fields at the bottom of each column. I would like to move them to the top, right after the <thead> </thead>. The basic HTML code for ...

Transitioning hover effects with absolutely positioned elements

I am facing an issue where I have an image with a centered absolutely positioned link on top of it. When I hover over the image, there are transition effects in place which work perfectly fine. However, when I hover over the link, these transition effects ...

Adjusting Column Order in Bootstrap 4 for Mobile Screens

I have a unique challenge regarding changing the order of columns in Bootstrap for mobile devices. While I have come across many Stack Overflow questions on this topic, none seem to address changing the order of columns that are on different rows. <d ...

I'm wondering if there is a method for me to get only the count of input fields that have the class "Calctime" and are not empty when this function is executed

Currently, I am developing an airport application that aims to track the time it takes to travel between different airports. In this context, moving from one airport to another is referred to as a Sector, and the duration of time taken for this journey is ...

Is it a universal rule for embedded css to take precedence over external css?

In my previous studies, I had learned that embedded CSS always takes precedence over external CSS. However, I have discovered that the styles that come last in the code actually prevail. Consider the following code snippet where I have used color:green; i ...

Applying a distinct CSS style to the final entry of each list item

Is there a way for me to assign a different style for the last entries in my code? <?= $k % 2 == 1 ? 'news-figure' : 'news-figure-b' ?> ...

Efficient Techniques for Concealing and Revealing Navigation Menus using HTML, CSS, and JavaScript

I need help making the menu icon toggle the navigate menu between showing and hiding when clicked on the top right corner of the screen. For better understanding, here is an accompanying image: https://i.stack.imgur.com/oy6d9.png However, the current co ...

Generate a text input field within a dropdown menu

Below is an example of my basic HTML code for a drop-down list: <span id="Div_List"> <label for="Gender">For:</label> <select name="Gender" id="Sex"> <option value="1">1000mtr</option> <option val ...

The picture above just won't stay within the div

Ensuring my website is responsive across all devices has been a priority for me. However, I have encountered an issue where, upon scaling down the size of the web browser, an image positioned within a div starts to overflow. While attempting to address thi ...

Can the value of the currently selected option in a select box be obtained without needing to submit the form?

I'm currently working on a project and facing a roadblock with the following task: My goal is to extract the selected value from a dropdown menu and utilize it in my PHP script. The challenge here lies in capturing the chosen option without requirin ...

Brick-themed HTML/CSS elements drift away from each other

I'm currently designing an image collage for my website and attempted to use masonry for the layout. However, when I adjust the size of the blocks, they seem to drift apart, creating large gaps between each block. Any suggestions on how to resolve thi ...

Build a table with consistent columns and flexible rows utilizing CSS and HTML

Just starting out with CSS/HTML and looking for guidance on creating a table with a variable number of rows. Any tips on how to achieve this using CSS? I'm aiming to replicate a table with a similar structure, but struggling to figure out how to defin ...

Discovering all jQuery functions employed in a JavaScript file can be accomplished through the utilization of regular expressions

I have a somewhat unconventional idea that I want to share. The project I'm currently working on has an old front-end codebase that is causing the website to run slowly, with jQuery being a major factor. My plan is to develop a tool that can analyze a ...

Steps to dynamically modify a class upon clicking

Imagine having a sequence of div elements: <div id='d-1' class='hidden'>this one<br /> <button onclick='next();'>Go to Next</button> </div> <div id='d-2' class='show'&g ...

Customizing and adjusting the CSS for all individuals accessing the website

I am in the process of developing a system that will notify users in the office when a specific individual is busy and cannot answer the phone. How can I implement a feature where clicking "engaged" changes the color of the availability box to red on thei ...

Leveraging the power of Ajax to dynamically submit a single form nested within a forEach iteration

I'm currently working on a database query that retrieves all user posts. This query is then used in a forEach loop to generate a post for each result: for($indexPost=0; $indexPost < $postCount; $indexPost++) { //Code for handling the post echo&l ...

Checkbox loses its check mark when window is resized

My solution for toggling the sidebar visibility on mobile and tablet devices using CSS3 checkboxes is working perfectly. However, I encountered an issue where resizing the browser window causes the sidebar to become unchecked, resulting in the navigation b ...

What is the best way to iterate over my JSON data using JavaScript in order to dynamically generate cards on my HTML page?

var data = [ { "name":"john", "description":"im 22", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c7d7e7f0c2b212d2520622f">[email protected]</a>" }, { "name":"jessie", ...

Tips for Choosing Certain List Items in a Responsive Bootstrap Navigation Menu for WordPress

I've put together a sleek bootstrap navbar menu for WordPress. If you want to check out the menu design, you can view it by clicking on this link: here There are still some tweaks that need to be made though. Specifically, I need to add a box around ...