Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:09:16+00:00 2026-05-31T05:09:16+00:00

<svg width=5cm height=3cm viewBox=0 0 500 300> <path id=path1 d=M100,250 C 100,50 400,50 400,250

  • 0
<svg width="5cm" height="3cm"  viewBox="0 0 500 300">
<path id="path1" d="M100,250 C 100,50 400,50 400,250"
    fill="none" stroke="blue" stroke-width="7.06"  />
<circle r="17.64" fill="red">
<animateMotion dur="6s" repeatCount="1" rotate="auto" >
   <mpath xlink:href="#path1"/>
</animateMotion>
</circle>
</svg>

If I write the svg in plain html/svg file, it works fine, the circle animates correctly.
But if I add the circle element dynamically via javascript, circle was added, but it didn’t animate. What’s wrong? js code:

    var svg = $("svg"); //use jquery
var circle = document.createElementNS("http://www.w3.org/2000/svg","circle");
circle.setAttribute("r", "5");
circle.setAttribute("fill", "red");
var ani = document.createElementNS("http://www.w3.org/2000/svg","animateMotion");
ani.setAttribute("dur", "26s");
ani.setAttribute("repeatCount", "indefinite");
ani.setAttribute("rotate", "auto");
var mpath = document.createElementNS("http://www.w3.org/2000/svg","mpath");
mpath.setAttribute("xlink:href", "#path1");
ani.appendChild(mpath);
circle.appendChild(ani);
svg.append(circle);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:09:17+00:00Added an answer on May 31, 2026 at 5:09 am

    Use setAttributeNS on “mpath” instead of setAttribute.

    mpath.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#path1");
    

    Here’s a demo: http://jsfiddle.net/zh553/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var svgcanvas = d3.select(body).append(svg:svg) .attr(width, 725) .attr(height, 500); A sample of my data set
Given this html+svg <div id=svg style=width: 300px; height: 300px> <svg xmlns=http://www.w3.org/2000/svg width=300 height=300> <svg
Here's my CSS: #social #twitter { background-image: url(../img/twitter.svg); max-height: 32px; max-width: 32px; } And
I have a construction: <div id=div> <svg xmlns=http://www.w3.org/2000/svg version=1.1 id=svg> <image x=2cm y=2cm width=5cm
I need to be able to select the width and height of an svg
I would like to read in a SVG file, determine its width and height
I've created a monster animated SVG file with over 3000 paths. Each path animates
I have SVG string and I need to extract its two attributes: width and
Assume I have a histogram script that builds a 960 500 svg graphic. How
I have a HTML code, <div class=layout data-type=renderingCanvas data-format=canvas style=width:100px; height:100px> </div> where data-type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.