Find class name of SVG element

Cute_Ninja picture Cute_Ninja · Jun 26, 2014 · Viewed 11.6k times · Source

How can I find the class name of SVG attribute?

If it was div it would have been {reference to DIV}.className

But, this doesnt work exactly the same way with SVG element

Is there any jquery or javascript method/attribute to get the classes of a SVG element?

See below what I have tried:

enter image description here

Answer

mdlars picture mdlars · Jun 26, 2014

Here's a jsfiddle: http://jsfiddle.net/Ujp76/

<body>
   <svg class="c1"></svg>

   <script>
      window.addEventListener("load", function () {
          var className = document.querySelector("svg").getAttribute("class");
          console.log(className);
      });
   </script>
</body>