SVG child element attribute grabbing

Discussion in 'JavaScript' started by everlive, Feb 24, 2016.

  1. #1
    Hey guys, I am trying to get see if their is a way to grab the <polygon> height and width. Unfortunately, <path> and <polygon> do not seem to have them and I was wondering if there was a way to do it.

    So far I have:
    
        <svg class="polu" preserveAspectRatio="xMidYMid meet" viewBox="0 0 100 100" width="300px" height="300px">
           <a class="polu2" xlink:href="deviantart.com" >
             <polygon class="polu3" fill="red" stroke="brown" points="45,2 2,45 45,88 88,45"/>
           </a>
         </svg>
    
    Code (markup):
    
        (function(){
    
           "use strict";
    
           window.onload = function() {
             polygoChk();
           };
    
           function polygoChk() {
             var polu = document.getElementsByClassName('polu3')[0];
             
             var polyHeight = polu.getAttribute('width');
             
             console.log(polyHeight+ " polygon width");
           };
    
         })();
    
    Code (markup):
    returns null or 0 depending on what I use. So, I'm thinking if I can't get the <polygon> dimensions is there a way to grab the aspect box around the <polygon>?
     
    everlive, Feb 24, 2016 IP
  2. denis bayly

    denis bayly Well-Known Member

    Messages:
    110
    Likes Received:
    29
    Best Answers:
    6
    Trophy Points:
    105
    #2
    denis bayly, Feb 24, 2016 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,291
    Likes Received:
    1,698
    Best Answers:
    31
    Trophy Points:
    475
    #3
    qwikad.com, Feb 24, 2016 IP