I'm trying to learn SVG for the first time but the code seems to have an issue with my block comments. I'm using:
/* This is my * block comment */
And when I run my code, I get the following error:
'return' statement outside of function line: 116, column: 4
That so happens to be immediately before my block comment.
The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .
Scalable Vector Graphics (SVG) is an XML-based vector image format for defining two-dimensional graphics, having support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999.
As SVG is XML, you can use XML style comments:
<!-- comment -->
For example:
<g onclick = "setScale(1)"> <rect id = "scale1" x = "120" y = "10" width = "30" height = "30" fill = "#ffc" stroke = "black"/> <!-- this text describes middle rectangle --> <text x = "135" y = "30" text-anchor = "middle">M</text> </g>
Or you can exclude some part of code:
<!-- this group is disabled for testing <g onclick = "setScale(1)"> <rect id = "scale1" x = "120" y = "10" width = "30" height = "30" fill = "#ffc" stroke = "black"/> <text x = "135" y = "30" text-anchor = "middle">M</text> </g> -->
An svg document is much the same as an html document as far as the DOM is concerned.
This line will break in all browsers:
svgDocument = evt.getTarget().getOwnerDocument();
And could simply be replaced by:
svgDocument = document;
Actually there's no real need to create a variable svgDocument
since document
is always defined and referring to the current document (the svg).
Please read https://jwatt.org/svg/authoring/ and in particular https://jwatt.org/svg/authoring/#asv-getters-and-setters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With