开发者

How do I find the :hover css atributes of an element?

开发者 https://www.devze.com 2023-02-04 03:49 出处:网络
I know I can get the color of an element by doing var col = $(\'a\').css(\'color\'); However how do I get the color of that same element when it\'s hovered?Would sending a mouseover event to the e

I know I can get the color of an element by doing

var col = $('a').css('color');

However how do I get the color of that same element when it's hovered? Would sending a mouseover event to the element trigger a hover state and if I开发者_如何学Go then read the color would I get the hover color?

(this code is running on somebody else's page and I'm looking to get link colors to pass to an iframe so that it can match style with the parent).


I don't know of any javascript library's that attempt to predict css attributes, so yes, you would have to trigger the event and read it when triggered.


I think the question is how do you tell what the :hover color would be without the users actually hovering - sending 'mouseenter' and 'mouseover' events to the element doesn't trigger the browser hover state.


$("a").mouseover(function(){
    var color = $(this).css("color");
});

See a working demo

0

精彩评论

暂无评论...
验证码 换一张
取 消