I am trying to dynamically wrap certain svg
elements like rect
,text
,etc into a single g
using javascript (jQuery)
This is how the svg looks initially
<div id="container">
<svg ...>
<rect .../>
<circle .../>
<text ...>...</text>
</svg>
</div>
The script (based on the helpful answers I received @ Inserting a (g) node in the middle of a tree (SVG) using jQuery) that I use to wrap into the g
tag.
$("#container svg > *").wrapAll('<g id="parent" />');
The transformed svg
looks like this
<div id="container">
<g id="parent">
<svg ...>
<rect .../>
<circle .../>
<text ...>...</text>
</svg>
</g>
</div>
But nothing shows up on the UI. Even firebug shows the g
to be grayed out (like it does for hidden elements).
calling $("#parent").show();
works in sometime cases but not all
Questions:
- Why does the
g
that is dynamically created, hidden by default? - Why does
$("#parent").show()
work inconsistently? - Is there another (better) way of grouping grouping elements dynamically?
- I am totally new to SVG, but relatively comfortable with jQuery and DOM manipulation. Is the way that I am treating SVG as just-another-tag wrong?
Tried on both Firefox (15.0.1) and Chrome (21.0.1180.89) with same results