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

  • SEARCH
  • Home
  • 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 7177403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:42:24+00:00 2026-05-28T16:42:24+00:00

I have an inline SVG with in an HTML5 document, and would like to

  • 0

I have an inline SVG with in an HTML5 document, and would like to add with jQuery (or plain JavaScript if needed).

I know how to add a rect, circle or other form, but I’m not able yet to reuse an existing .

Here is a test on jsFiddle: http://jsfiddle.net/nhoizey/uDVbn/

The SVG:

<svg width="300" height="300">
  <symbol id="piece"><circle cx="50" cy="50" r="40" fill="green" /></symbol>
  <circle cx="70" cy="90" r="20" stroke="blue" fill="white" />
</svg>

The JavaScript:

// it works!
var rect = $(document.createElementNS("http://www.w3.org/2000/svg","rect"))
  .attr({
    x: 10,
    y: 30,
    width: 50,
    height: 70,
    stroke: "red",
    fill: "white"
  });
$("svg").append(rect);

// it doesn't work
var newPiece = $(document.createElementNS("http://www.w3.org/2000/svg","use"))
  .attr({
    "xlink:href": "#piece",
    transform: "translate(100, 100)"
  });
$("svg").append(newPiece);

I know there is a jQuery SVG plugin, but would like to keep it as light as possible.

  • 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-28T16:42:25+00:00Added an answer on May 28, 2026 at 4:42 pm

    The proper way to add href attribute is to use setAttributeNS.

    useElement.setAttributeNS("http://www.w3.org/1999/xlink", 'href', '#piece');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working with an HTML5 document with inline SVG and javascript animation. I'd
I want to create inline SVG graphics using Javascript. However, it seems like createElementNS
I currently have problems aligning inline SVG correctly inside a bounding DIV, like in
The following practice is fairly commonplace in the inline JavaScript I have to work
Is it possible in Gtk+ to have an add-tab button inline with the tabs
I have a stand-alone svg file that displays without problems. It includes some inline
I have inline jQuery UI DatePicker and need to customize format and look of
I have this code inline in document ready if($.cookie('form_seen') == null) { $(#dialog_form).dialog(open); }
Say I have several inline-block div tags, like this <div class=image> </div> <div class=image>
i have an inline svg with foreignObject elements which contain xhtml fragments. however, the

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.