Assume I have the following CSS:
div {
-my-foo: 42;
}
Can I later in JavaScript somehow know what the value of the -my-foo CSS property is for a given div?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think you can access invalid property names, at least it doesn’t work in Chrome or Firefox for me. The CSSStyleDeclaration simply skips the invalid property. For the given CSS:
style:CSSStyleDeclarationobject contains only the following keys:However, interestingly this is what the DOM-Level-2 Style spec says:
implying that the CSSStyleDeclaration object ought to have listed the
-my-fooproperty in the above example. Maybe there is some browser out there which supports it.The code I used for testing is at http://jsfiddle.net/q2nRJ/1/.
Note: You can always DIY by parsing the raw text. For example:
but that seems like a lot of work to me, and not knowing your reasons for doing this, I can’t say if a better alternate for your problem exists.