Toggle attribute selector CSS javascript -
i want toggle "fill: #000;" css property "svg [id^='_']".
normally i'd use this, can't use because "svg [id^='_']" isn't element, right?
pub.toggleclass = function(el, classname) { if (el.classlist) { el.classlist.toggle(classname); } else { var classes = el.classname.split(' '); var existingindex = classes.indexof(classname); if (existingindex >= 0) classes.splice(existingindex, 1); else classes.push(classname); el.classname = classes.join(' '); } };
when try toggleclass says "uncaught typeerror: cannot read property 'split' of undefined"...
i've tried doing this: document.stylesheets[1].addrule("svg [id^='_']", 'fill: #000;');
isn't working cross-browser , it's not toggling... because feeling there simpler way this..
update 1
i'm going try library: https://github.com/box9/jss
i able use toggleclass putting attribute selector in class adding. rather try add style onto existing attribute selection, lot simpler.
.monotone [id^='_'] { fill: #000; }
Comments
Post a Comment