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:
Searching for parents
Searching for parents
- Attachments
-
- test_01.svg
- Searching for parents
- (1.34 KiB) Downloaded 263 times
Re: Searching for parents
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:
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" />