Sohaib Mohammed Sohaib Mohammed - 2 months ago 11
Javascript Question

vivus.js - How to select SVG by Class

Is there a way to select SVG by Class instead of ID , Like this:

<svg class="mySVG">
<path...>
<path...>
<path...>
</svg>

<script>
new Vivus('.mySVG', {duration: 200}, myCallback);
</script>

Answer

Since you can have multiple elements with same class

  var els= document.getElementsByClassName("mySVG");

  for (var i = els.length - 1; i >= 0; i--) {
    new Vivus(els[i], {duration: 200}, myCallback);
  }
Comments