8detect
10/27/2017 - 3:09 PM

XJS - jQuery.parseCss

/**

  • added 27-10-2017,
  • v1.0
  • css = "attr='';abc='';..."
  • @param string css style string
  • @returns object */
/**
 * added 27-10-2017, 
 * v1.0
 * css = "attr='';abc='';..."
 * @param string css style string
 * @returns object
 */
jQuery.parseCss = function (css) {
    var pairs = css.split(';');
    var obj={};
    for (var p of pairs){
        p = p.trim();
        if (p=='') continue;
        p = p.split(/\s*:\s*/);
        console.log(p)
        var attr=p[0];
        
        var value = '';
        if (p[1]!=null) value=p[1].replace(/'"/);
        
        obj[attr]=value;
    }
    return obj;
};