Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
Getting an element from a <path> from a svg path in HTML

I am trying to get svg path string out of svg path in html. Ler's suppose I have a svg Path in this format.

<path d="M 0 68.5 C -1.56977e-13 30.6685 184.011 -1.30814e-14 411 -3.92443e-14 C 637.989 -5.23258e-14 822 30.6685 822 68.5 C 822 106.332 637.989 137 411 137 C 184.011 137 -1.56977e-13 106.332 0 68.5 Z" fill-rule="evenodd" fill="none" stroke="none"></path>

How can I get the value inside path tag, specially value inside d attribute.

There is one way to get it by doing some basic operation like getting index of M and fill, but that is not a very good solution for this.

        var htmlStr = elem.outerHTML;
        var start = htmlStr.indexOf("M");
        var end = htmlStr.indexOf("fill");
        var str = htmlStr.substring(start, end);
        str.replace("\"", "");
        str.trim();

Can anybody suggest some generic solution for this?

Note: path tag does not have any Id, and I can't create one as it is coming from other service.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can juste use the attributes of path like that :

const pathId = document.getElementById("pathId");
const dValue = pathId.attributes["d"].value;

console.log(dValue);
<path id="pathId" d="M 0 68.5 C -1.56977e-13 30.6685 184.011 -1.30814e-14 411 -3.92443e-14 C 637.989 -5.23258e-14 822 30.6685 822 68.5 C 822 106.332 637.989 137 411 137 C 184.011 137 -1.56977e-13 106.332 0 68.5 Z" fill-rule="evenodd" fill="none" stroke="none"></path>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda