My javascript is included in X's site, but I don't have any other control over her site or where she includes it. If she's styled #element
, I want to leave it alone, but if she hasn't, I've got a stylesheet I'll inject in <head>
. Is there any way to detect whether or not she's styled it?
Checking it's height is 0 or 1 fails because it's got some content in it and the browser makes default decisions.
Any way for javascript/jquery/other framework to tell the CSS specificity of a style would answer this and be incredible.
In Chrome, if you right click on an element and "inspect," then view the styles in the "Computed" tab then you should see what styles are affecting the element.
This rule will affect every p on the page, whereas the inline style will affect only the <p> it's written in. Cascading works the same way, however, so the <strong> element inside the <p> will be blue with big text regardless of whether you decide to use inline styling or CSS rules.
CSS Inheritance This behavior means that a style applied to an element is inherited by its descendent elements. By default, the primary properties that have this behavior are text ones, such as font-family , font-size , color , text-align , and other typography properties.
It is possible to specify several alternate styles using multiple Link headers, and then use the rel attribute to determine the default style. In the following example, "compact" is applied by default since it omits the "alternate" keyword for the rel attribute.
For inline style, it's quite easy: you can just access to element.style
object and check the property you want to – or use element.hasAttribute('style')
to check if the attribute is defined in the HTML.
For CSS rules applied by stylesheet, I would suggest to you to take a look at "Is it possible to check if certain CSS properties are defined inside the style tag with Javascript?" that it's quite similar from what are you asking.
Using the approach described there, is also quite easy filtered the rules that have only the #element
selector in, if you want to filter out any generic rule (like tag ones).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With