How to get css hover values on click?

被刻印的时光 ゝ 提交于 2019-12-02 08:35:31

You could do something like this, where you create your own list of css properties that would be applied to that element (assuming you had a list) and then cycle through them:

var cssList = ['text-decoration','opacity','filter'];

$(".test").click(function(){
    for(x in cssList){
        alert($(this).css(cssList[x]));
    }    
   return false;
})

Example: http://jsfiddle.net/jasongennaro/GmWCz/

Of course, you could take this all the way and add all the properties, if that is what you needed.

HTML changes, adding an extra class:

<a href="" class="test apply-hover">Click Me</a>

CSS changes, modify hover selector:

a.test.apply-hover:hover { ...

JS changes, remove 'apply-hover' class on click event:

$(this).removeClass('apply-hover');

Example: http://jsfiddle.net/bGKE7/1/

The right way to do this seems like it would be to create a style tag and re-assign the hover property directly. I have a working example here.

(Credit where credit is due -- I got that from a function defined here)

Take a look here

It's a re-implementation (read: duck punching) of the .css() method

And here's the DEMO

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!