Retrieve CSS hover values using jQuery

When the page is loaded, I need to execute a function that retrieves the CSS background image settings as well as the hover background image setting, which I intend to use in a different way.

The only technique I have come across requires an actual mouseover event on the element to obtain the value.

Does anyone know of another method?

Here's how you can get a non-hover CSS value:

$(this).css('background-color');

Answer №1

In order to achieve this task, it is necessary to retrieve values directly from the stylesheet. The approach involves iterating through each stylesheet within document.styleSheets, and then iterating through each rule in .cssRules or .rules, searching for a .selectorText that matches your desired criteria.

To streamline this process, I developed a (small) library specifically for this purpose - JSS. For instance, if you have a selector such as #someId:hover, by utilizing JSS, you can obtain its background-color property like so:

jss('#someId:hover').get()['background-color']

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

Utilize the bootstrap grid to align content into 4 columns evenly

I have the following code snippet: <div class="panel-body"> <div class="col-sm-6"> <label class="head6">Business Name : </label><span class="head9">'.$name.'</span> </div> <div ...

Is there a way to have two SVG files displayed on a single HTML page at the same time

Currently, I am facing an issue with my graphs. I have a line graph and a boxplot, but the boxplot is appearing below the line graph when I want it to be next to it. Any suggestions on how I can achieve this layout? Thank you! I attempted to use 2 differe ...

Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far. Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it ...

Replace the current CSS styles of a pre-installed package

I recently added a package for a type writer effect, but I'm having trouble with it not overriding the CSS styles I've set in the component. Here's an example of what I have: <template> <v-row class="hero" align-content= ...

Image Not Displayed on Page

I am facing an issue where I have a div class 'breadcam_bg' with an image url, but the image is not being displayed on the page even though the console detects the div. html <div class="bradcam_area breadcam_bg"> This div! & ...

Clear input field after successful submission using jQuery

When the form is submitted correctly, I want to clear the input values. However, a problem arises - if the inputs are not filled in, they get erased. Any help would be greatly appreciated. Here's my code: $(document).ready(function(){ $("#Insert" ...

Creating a scrolling list group in a single column that moves in sync with another longer column

When working with two columns in Bootstrap, such as col-4 and col-8, how can you ensure that a list-group stays fixed within its column and vertically aligned even when the content in the other column is scrolled down? Dealing with this responsively can b ...

The issue with color swapping in Internet Explorer is not functioning correctly due to

I am facing an issue with a jQuery script that I have created to change the background colors of rows in a large table. Unfortunately, it seems to be malfunctioning on Internet Explorer versions 6 through 9. Below is the snippet of code I am using: <s ...

Unable to open javascript dialog box

One issue I encountered involves a jqGrid where users have to click a button in order to apply any row edits. This button is supposed to trigger a dialog box, which will then initiate an ajax call based on the selected option. The problem lies in the fact ...

Classic leading and CSS line-height traditional styling

The CSS specification dictates that line-height should be implemented by dividing the specified value by two and applying the result both above and below a line of text. This significantly differs from the traditional concept of leading, where spacing is ...

Cross-Origin Resource Sharing (CORS) implementation in Symfony using jQuery, FOSRestBundle, and NelmioCors

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ TL;DR: Edit (before reading the whole thing): This issue has been resolved by me due to a silly mistake in my code, unrelated to CORS or anything else. If you still want to re ...

Internet Explorer reverts back to default fonts once the webpage has completed loading

I'm encountering a minor problem with a website I'm currently working on. My CSS and web fonts are from Fonts.com, and everything seems fine except in Internet Explorer. Initially, the page displays with the fonts correctly applied, but once the ...

A JointJS element with an HTML button that reveals a form when clicked

How do I bind data to a cell and send it to the server using the toJSon() method when displaying a form on the addDetail button inside this element? // Custom view created for displaying an HTML div above the element. // ---------------------------------- ...

String object causing jQuery selector to malfunction

const newHTML = '<html><head><title>Hello</title><link rel="apple-icon-touch-precomposed" href="image.jpg" /></head><body></body></html>'; alert($(newHTML).find('link[rel="apple-icon-touc ...

Can someone guide me on the proper way to utilize jQuery Masonry reload function?

The following script fades out tiles on the page that do not match the user's input. While this functionality is working perfectly, I am facing an issue where Masonry does not realign the tiles after they fade out. Sample HTML Code- <article clas ...

Insert the video link and preview it with live option

Currently working on a form that allows users to input a video URL. The form will be a standard input field where they can enter a URL such as: http://video.google.com/videoplay?docid=1299927595688205543 I want to include a button within the form labeled ...

Converting Umbraco Json to a CSS class named "[]"

I'm currently using Umbraco with the data-type grid layout and I am trying to add custom settings (CSS classes) to each row/cell. The results are somewhat working, but I want to improve it. Here's the user interface: https://i.stack.imgur.com/iY ...

Encountering issues with jQuery ajax requests

I am encountering an issue with my AJAX request to the controller. Despite multiple attempts, I cannot identify the root cause of the error. Below is the code snippet: Unfortunately, the HTTPS constant is predefined and cannot be shared here! $(" ...

Arrange two divs on either side of the center div when on a smaller screen

Looking for a straightforward approach to achieve this. Imagine it as follows: [A][__B_][A] to [A][A] [__B_] I hope that explanation is clear, but I'm happy to provide more details if necessary. Thank you in advance! ...

Dividing an array in PHP using Ajax

Hey there, I have successfully sent data from PHP to Ajax using Json but now I need help in splitting the response. Can anyone guide me on how to alert each element separately? $.ajax({ url:"myHandler.php", type:"POST", ...