How can I tell if a particular CSS property is inherited with jQuery?

后端 未结 7 830
自闭症患者
自闭症患者 2020-11-29 03:49

This is a very simple question, so I\'ll keep it really brief:

How can I tell if a particular DOM element\'s CSS property is inherited?

Reas

7条回答
  •  时光说笑
    2020-11-29 04:41

    I know this is an old question, however I thought I'd share what I've done with Josh's answer, viz: modified it to remove the css if it was inherited, and turned it into a jQuery plugin. Please feel free to shoot it down, but so far it is working for me :-)

    $.fn.isInheritedStyle = function(style) {
        var current = this.css(style);
        this.css(style, 'inherit');
        var inherited = this.css(style);
        if (current == inherited)
            this.css(style, '');
        else
            this.css(style, current);
        return (current == inherited);
    }
    

提交回复
热议问题