Using JQuery I am not able to remove class and add class to my SVG -
i trying use jquery click event remove class , add different class svg object not changing fill expected.
$(".seat").click(function (event) { var result = $(this).data("seat"); var state = $(this).data("state"); $(this).removeclass( "seat" ).addclass( "taken" ); result = result +" - "+ state; $("#statusbox").html(result); });
my js fiddle here
unfortunately, class
not work same svg tags standard html, @ least in respect jquery. rather treat class, need treat attribute.
$(".seat").on('click',function(e){ var $this = $(this), $data = $this.data(); $this.attr('class','taken'); $("#statusbox").html($data.seat +" - "+ $data.state); });
since removing class present , giving new class, assigned attribute of class
new value of taken
. if actual code more complex multiple classnames, may need creative, concept remains same ... replacing part of attribute's string value.
i updated code bit more efficient, hope thats cool. here working jsfiddle.
Comments
Post a Comment