SVG propietarioElemento Propiedad

La propiedad OwnerElement de SVG devuelve el elemento OwnerElement del elemento Attr dado.

Sintaxis:

name = attribute.ownerElement

Valor de retorno: esta propiedad devuelve el elemento propietario del Attr.

Ejemplo 1:

HTML

<!DOCTYPE html>
<html>
  
<body>
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg">
          
        <!-- A link around a text -->
        <text id="example" x="20" y="20">
            Click me
        </text>
          
        <script>
            const element = document
                .querySelector("#example");
                  
            const attribute = element.attributes[0];
            console.log(attribute.ownerElement);
        </script>
    </svg>
</body>
  
</html>

Producción:


Ejemplo 2: 

HTML

<!DOCTYPE html>
<html>
  
<body>
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg">
          
        <!-- A link around a shape -->
        <circle id="example" cx="20" 
            cy="20" r="15">
            Click me
        </circle>
          
        <script>
            const element = document
                .querySelector("#example");
                  
            const attribute = element.attributes[0];
            console.log(attribute.ownerElement);
        </script>
    </svg>
</body>
  
</html>

Producción:


Publicación traducida automáticamente

Artículo escrito por taran910 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *