I wrote this function to save headaches when I move CSS around(it converts CSS strings to objects). I would like to be able to use it as a drop in for the .css() function.
jQuery.fn.cCSS = function(css) {
return this.each(function(){
var css_obj = {};
var tmx = "";
ocss = css.split(";");
$.each(ocss, function (index, elem){
tmx = elem.trim().split(':');
if (tmx[0].length > 0)
css_obj[tmx[0]] = tmx[1].trim();
});
return $(this).css(css_obj);
//return $;
});
};
})(jQuery);
My problem is when I use it in “fluent” notation I always get a null error.
Uncaught TypeError: Cannot call method ‘addClass’ of null
I’m a bit confused what has to be returned in order not to “break the chain”
You may want to look into what line number that error is. I don’t think it has anything to do with this function. The function itself worked for me.
http://jsfiddle.net/R8UtV/ << Demo
Especially since addClass isn’t called, unless you’re running it when you call the function?
ie