javascript - d3.js to remove two elements with matching attribute when clicked consecutively -
i have 2 elements identical href attributes. clicked, adding class. if, in addition, href of element clicked first equal href of element clicked second, filtered out.
removebubble = function(d) { var currentid; currentid = idvalue(d); d3.select(this).classed("clicked",true); // on click add class if (d3.selectall(".clicked").length === 2 && // 2 elements class clicked d3.select(this).prev.attr("href") === // href of 1st elem d3.select(this).next.attr("href")) // href of 2nd elem { // filter here } };
the task: 1. check if elements clicked have matching href
how can achieve .prev() , .next() - jquery assessors - effect in d3.js ?
so far: uncaught typeerror: a.target.classname.indexof not function
here final working solution comments:
removebubble = function(d) { var currentid; currentid = idvalue(d); // when clicked attach class var clicked = d3.select(this).classed("clicked",true); // ascribe href of elements class clicked variable var clicktext = d3.selectall(".class1.clicked").attr("href"); var clicklabel = d3.selectall(".class2.clicked").attr("href"); // if no match remove class clicked , update // else remove elements , update if ( clicklabel !== clicktext){ console.log("it's not match !"); d3.selectall(".clicked").classed("clicked",false); update(); return d3.event.preventdefault(); } else { console.log("its match !"); data = data.filter(function(e) { return idvalue(e) !== currentid; }); } update(); return d3.event.preventdefault(); };
the point remove class used identify elements in case when 2 elements different href values clicked consecutively: remove class, update = start fresh.
Comments
Post a Comment