Searching for parents

Discuss SVG code, accessible via the XML Editor.
Alikrus
Posts: 5
Joined: Thu May 27, 2010 8:14 am

Searching for parents

Postby Alikrus » Fri Sep 23, 2011 6:30 am

Hi!
Few day later i starting my own tiny game engine to play svg-animation.
When i trying to improving this, i erase out lots of id. But one problem i find as very hard!

Why i can to find all <use ... href='#Ball'/> directly from all using of my <defs><g id='Ball'> in my script?

Thanks!

Here my code:
Attachments
test_01.svg
Searching for parents
(1.34 KiB) Downloaded 263 times

coiner
Posts: 19
Joined: Mon Mar 14, 2011 5:21 pm
Location: NY

Re: Searching for parents

Postby coiner » Sat Sep 24, 2011 4:57 am

I'm not sure if this is what you want but here goes...

You could give all of the <use> tags a class of 'Ball' or similar and then use document.getElementsByClassName('Ball')

Example:

Code: Select all

<script type="text/javascript">
  <![CDATA[

    function getBalls() {
      return document.getElementsByClassName('aBall');
    }

  ]]>
</script>

<defs>
  <g id="ball">
    <!-- whatever ball is -->
  </g>
</defs>

<use id="ball1" class="aBall" xlink:href="#ball" />
<use id="ball2" class="aBall" xlink:href="#ball" />
<use id="ball3" class="aBall" xlink:href="#ball" />
<use id="ball4" class="aBall" xlink:href="#ball" />
<use id="ball5" class="aBall" xlink:href="#ball" />


Return to “SVG / XML Code”