javascript - click function to only execute on certain data names -


i have click:function interactive jquery map.

the below defines "active color states" -- color states turn after being clicked. alter work / execute on few states choose. every state has data.name it's abbreviation. eg. 'oh' 'ca' 'tx" 'ny' etc. active color removes upon click states (as below) need ability have work select chosen states, not 50.

click: function(c, l) {     $("#map > svg > path").each(function() {             $(this).css("fill", "")         }),         $("#" + l.name).css("fill", "#ffc600"), 

define array allowed states var clickable = ['oh','ca','tx','ny']; , use indexof see if clicked state in it..

try

click: function(c,l){   var node = $(l.shape.node),       siblings = node.siblings('path');    siblings.css('fill','');   if (clickable.indexof(l.name) > -1){     // select     node.css('fill','green');   } } 

demo @ http://codepen.io/gpetrioli/pen/dplgvg


you styling css, though
(example requires browsers support classlist property)

click: function(c,l){   var active = $(l.shape.node)                  .siblings('.selected')                  .get(0);    // if there selected path   if (active) {     // de-select     active.classlist.remove('selected');   }   // if clicked node in list of clickables   if (clickable.indexof(l.name) > -1){     // select     l.shape.node.classlist.add('selected')   } } 

demo @ http://codepen.io/gpetrioli/pen/dplgrg


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -