How to get the text of an svg desc element with javascript
right now I have a group of svg elements (circle, rect, path, etc.).The actual document looks something like this.
<desc>Some Text</desc>
<rect id='a0' fill='green' ...>
So when you you strip the a from the id you would get the corresponding desc element. I do this with the following code:
var WW = document.getElementsB开发者_JS百科yTagName('desc')
var ZZ = evt.target.id
ZZ = ZZ.split('a')
ZZ = ZZ[1]
alert(WW[ZZ].firstChild)
But the only thing the is returned in the alert right now is:
[object Text]
Anybody have any ideas or suggestions? Any help would be great.
I'd try
alert(WW[ZZ].firstChild.data);
To answer the main question (How to get the text of an SVG desc
element with JavaScript), this would nowadays work fine:
document.querySelector( 'desc' ).textContent
精彩评论