Sunday, December 4, 2016

Possible jQuery bug - jQuery, get fill color of a selector

jQuery seems to return "rgb(0,0,0)" when inline css value for "fill" property is not set.

In a call like this:

var ret = jQuery(".selector").css("fill");

Variable ret is set to "rgb(0,0,0)" when inline css value for "fill" is missing on the element.

Better approach is to use each() and iterate through all elements manually. Even pure JS can be used for this:

var ret=jselem.style.fill;

Also, to delete fill property from a single element, you can call:

jselem.style.removeProperty("fill") instead of jQuery(".selector").css("fill","").


No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...