Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

314
Views
Obtener un elemento de una <ruta> de una ruta svg en HTML

Estoy tratando de sacar la cadena de ruta svg de la ruta svg en html. Supongamos que tengo una ruta svg en este formato.

 <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>

¿Cómo puedo obtener el valor dentro de la etiqueta de ruta , especialmente el valor dentro del atributo d ?

Hay una forma de obtenerlo haciendo alguna operación básica como obtener el índice de M y llenar, pero esa no es una muy buena solución para esto.

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

¿Alguien puede sugerir alguna solución genérica para esto?

Nota: la etiqueta de ruta no tiene ninguna identificación y no puedo crear una porque proviene de otro servicio.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes simplemente usar los atributos de la ruta así:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!