0

Is it possible to retrieve the :active state CSS with jQuery? The reason why I ask this is because I'm trying to make dynamic code so I don't have to always tweak the jQuery when stylizing an element.

Edit

To elaborate, I don't want to .addClass() or .removeClass() because the class might not be the same for every element being affected by my jQuery code.

Edit 2

Let me further explain what I'm trying to do.

I'm trying to create a plugin for my own personal use, and instead of having to tweak the code every time I have a new element that will be affected by the plugin, I want it to grab what's already in the CSS so I won't have to lose time. What I'm trying to do is create a button with an :active state, and when the user clicks the button, it will "freeze" at that state (my thoughts are to grab the CSS from that state and put them in the .css() command). Now, the reason why I don't want to .addClass() or removeClass() because the :active state is going to differ from one button to another.

4

2 回答 2

1

:active无法从 jQuery 中检索和操作诸如此类的伪类。我没有尝试完成这项工作,而是有一个解决方法来解决这个问题。

首先创建一个只有:active零件的样式容器。例如:

<style id="activeLink">
    a:active { color: #f00; }
</style>

现在您可以使用 jQuery 来操作它,以检索当前样式

var curStyle = $("#activeLink").html();

修改样式

$("#activeLink").html("a:active { color: #000; }");
于 2013-04-21T02:54:07.723 回答
0
$('.somebutton').click(function(){
    $(this).css({...}) //insert whatever css
});
于 2013-04-21T02:46:55.670 回答