For example I have file main.css
#test { my-property-name: 10px; }
and index.html
<div id="test"></div>
Can I somehow get value of my-property-name for this div from js file?
For example I have file main.css
#test { my-property-name: 10px; }
and index.html
<div id="test"></div>
Can I somehow get value of my-property-name for this div from js file?
You can write your property as an attribute like so:
<div id="test" my-property-name="10px"></div>
And then you can use jQuery attr() function to retrieve it
var x = $("#test").attr("my-property-name");
alert(x);
See example here: http://jsfiddle.net/gkE4F/
attr is not CSS as I know...var my_element = document.getElementById('test');
var style_element = window.getComputedStyle(my_element);
var property_value= style_element.getPropertyValue('YOUR_PROPERTY_NAME');
You just need to get computed Style of the element. That will return all possible css properties within an object. And then you can get your required CSS property from that object.
And this is Pure JavaScript (if somebody doesn't understand)
Try this:
var allCss = window.getComputedStyle(document.getElementById('test')),
property_value= allCss.getPropertyValue("padding");
alert(property_value);
jsfiddle: http://jsfiddle.net/3ktu9/1/
my-property-name a valid css property? He was just giving an example through that.