Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda