Skip to content

Instantly share code, notes, and snippets.

@steckel
Created December 9, 2011 19:18
Show Gist options
  • Save steckel/1452894 to your computer and use it in GitHub Desktop.
Save steckel/1452894 to your computer and use it in GitHub Desktop.
A helpful little JQuery plugin I adapted from http://jsfiddle.net/ZcEUL/
$.fn.getInlineStyleObject = function() {
var $element, prop, props, rprops, str, styleObject, _i, _len;
$element = this;
str = $element.attr("style");
rprops = /[\w-]+(?=:)/g;
props = str.match(rprops);
styleObject = {};
for (_i = 0, _len = props.length; _i < _len; _i++) {
prop = props[_i];
if ($element[0].style[prop] != null) {
styleObject[prop] = $element[0].style[prop];
}
}
return styleObject;
};
$.fn.getInlineStyleObject = function() {
var $element, prop, props, rprops, str, styleObject, _i, _len;
$element = this;
str = $element.attr("style");
rprops = /[\w-]+(?=:)/g;
props = str.match(rprops);
styleObject = {};
for (_i = 0, _len = props.length; _i < _len; _i++) {
prop = props[_i];
if ($element[0].style[prop] != null) {
styleObject[prop] = $element[0].style[prop];
}
}
return styleObject;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment