Monday, March 7, 2016

SVG Add Class, Delete Class for Jquery


svgAddClass($(".myClass"), "selected_class");
svgRemoveClass($(".myClass"), "selected_class");

/**
  date: 26th Jan 2016
  Jquery doesn't support add class for svg currently
  workaround function for that
**/

function svgAddClass(svgElem, className){
  var classList = svgElem.attr('class') + " " +className;
  console.log('classList', classList);
  svgElem.attr('class', classList);
}

function svgRemoveClass(svgElem, className){
  var classList = svgElem.attr('class').replace(className, '');
  console.log('classList', classList);
  svgElem.attr('class', classList);
}

No comments:

Post a Comment