So if there is a css file linked to a webpage like:
<link href="style.css" rel="stylesheet" type="text/css">
and i want to read a certain property, e.g a div has className=’layout’ and i want to read the details of this property using JavaScript, how can i do that?
I have searched a lot but almost have no luck, please suggest.
You have got two options:
document.styleSheetsobject (not recommended, unless you want to get all specific style properties defined by a certain selector).getComputedStyleorcurrentStyle(IE) method to get the property value.In your example, attempt to get a certain property (let’s say:
color) of a div withclass="layout":Regarding comment at your question, another function:
The function below will ignore inline style definitions of the current element. If you want to know the style definitions inherited from a stylesheet (without inherited style definitions of the parent elements), traverse the tree, and temporary wipe the
.cssTextproperty, as shown in the funcion below: