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

304
Views
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 answers
Answer question

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