1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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:
    104
    Likes Received:
    28
    Best Answers:
    6
    Trophy Points:
    105
    #2
    denis bayly, Feb 24, 2016 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #3
    qwikad.com, Feb 24, 2016 IP