jquery - d3.js equivalent to $(this) -
i modify state of text node when clicked upon, apparently fail access correctly. when click, nothing happens (unless use jquery selector, , not command work). question is: d3.js equivalent $(this) ?
var buttons = svg.selectall(".button"); buttons.on("click",function(d){ var target = $(this).attr('target'); var visible = $(this).attr('visible'); if(visible==='1'){ svg.selectall(".bar."+target) .transition() .duration(500) .ease("elastic") .style('display','none'); $(this).attr('visible','0') .style('text-decoration','line-through'); }else{ svg.selectall(".bar."+target) .transition() .duration(500) .ease("elastic") .style('display','inline'); $(this).attr('visible','1'); $(this).removeclass('active'); } });
it turns out d3.select(this)
correct answer.
code :
var buttons = svg.selectall(".button"); buttons.on("click",function(d){ var target = $(this).attr('target'); var visible = $(this).attr('visible'); if(visible==='1'){ svg.selectall(".bar."+target).transition().duration(500).ease("elastic").style('display','none'); d3.select(this).attr('visible','0').style('text-decoration','line-through'); }else{ svg.selectall(".bar."+target).transition().duration(500).ease("elastic").style('display','inline'); d3.select(this).attr('visible','1').style('text-decoration',''); } });
Comments
Post a Comment