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 8851611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:11:50+00:00 2026-06-14T13:11:50+00:00

I am trying to implement a menu in Javascript with single menu-items being svg:g

  • 0

I am trying to implement a menu in Javascript with single menu-items being svg:g.
To mark an item as selected I would like to move another svg:g on top of the menu-item.

For this I need to get the bounding box of the menu-item (=svg:g) so I can apply the rect (x, y, width, height) to the other. I have not found a convenient way yet, for getting the bounding box of a svg:g.

The only way I can think of would be recursing into the children and calculating the bounding box (approximation) by hand. Is there a more elegant way?

  • 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-06-14T13:11:51+00:00Added an answer on June 14, 2026 at 1:11 pm

    You should just be able to use the getBBox method of your group element.
    e.g. http://jsfiddle.net/PFnre/1/

    var root = document.createElementNS("http://www.w3.org/2000/svg", "svg");
    document.body.appendChild(root);
    
    var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
    root.appendChild(g);
    
    var r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
    r.setAttribute("x", "50");
    r.setAttribute("y", "60");
    r.setAttribute("width", "100");
    r.setAttribute("height", "110");
    r.setAttribute("fill", "blue");
    g.appendChild(r);
    
    var c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
    c.setAttribute("cx", "150");
    c.setAttribute("cy", "140");
    c.setAttribute("r", "60");
    c.setAttribute("fill", "red");
    g.appendChild(c);
    
    var bbox = g.getBBox();
    
    var o = document.createElementNS("http://www.w3.org/2000/svg", "rect");
    o.setAttribute("x", bbox.x);
    o.setAttribute("y", bbox.y);
    o.setAttribute("width", bbox.width);
    o.setAttribute("height", bbox.height);
    o.setAttribute("stroke", 'black')
    o.setAttribute("fill", 'none');
    root.appendChild(o);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a tab menu just like the one in Stack Overflow.
I'm trying to implement a simple horizontal navigation menu that just shows a single
I'm trying to implement a click-like effect on my horizontal tab menu using opacity
I'm trying to implement a Jquery Javascript menu onto a webpage. Jquery code: $(.navigation
while i am trying to implement font menu item in notepad , im not
I am trying to implement a context menu in my QGraphicsItem subclass like so:
I'm trying to implement a 'preview' scenario when the user hover a menu item.
I'm trying to implement calling colorbox items from a dropdown menu. Using this example,
I'm trying to implement a Select All menu item for a ListView in a
I'm trying to implement a CSS menu and am having a problem with 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.