Let's take a look at some code:
<button id="test" class="ui-state-hover" value="Button">
In Context:
I'm utilizing the JQuery UI CSS class ui-state-hover
on an HTML button to ensure it always appears as if it's being hovered over. However, I've noticed that this class seems to disappear when I move my mouse away from another JQuery UI element. It seems like this might be expected behavior though.
<button id="test" class="" value="Button">
So, upon exploring further, I realized that there may be a line of code within that particular jQuery element similar to the following:
$('.ui-state-hover').on('mouseout', function(){$(this).removeClass('ui-state-hover');})
This code snippet removes the class from every element that possesses it. Therefore, I thought about creating a new class with the same styling as ui-state-hover
but with a different name. By assigning this new class to the element, I should be able to resolve the issue.
.MyCssClass = ui-state-hover
<butotn id="test" class="MyCssClass" value="Button">
Hence, I need to find a way to duplicate the content of one CSS class into another. Ideally, I would prefer a solution using pure CSS, but in case such an option doesn't exist, I am open to using JQuery or JavaScript.
Although I attempted something like the following, it didn't yield the desired outcome:
$('.MyCssClass').css($('.ui-state-hover').css());
Thank you for your help!
Update:
Here's a bit more detail on what I tried to accomplish.
I have numerous jQuery themes stored in a directory, and depending on the user's selection, I switch the .css file and refresh the page. As most themes share the same classes, they are interchangeable. For instance, the class ui-state-hover
may have a black background color in the ui-darkness jQuery UI Theme, while it could be gray in the ui-lightness jQuery UI Theme.
This is why I require a method to dynamically copy certain styles from these themes onto my own class during page load, rather than simply copying and pasting the entire .css file contents.
Additional Note:
Below is a fiddle demonstrating the issue I'm facing:
Please observe how the 'test2' button loses the ui-state-hover class when hovered over. I considered cloning the class to prevent this, but it appears to be a challenging task...