Why i can not get values of cx and cy ? its print some array. i need only 2 values
<!DOCTYPE html> <html> <body> <svg xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="50" fill="red" id="cir"/> </svg> <script> console.log(document.getElementById("cir").cx); console.log(document.getElementById("cir").cy); </script> </body> </html>
The cx
and cy
properties are SVGAnimatedLength
objects, not strings or numbers.
To get the actual value for cx
, you need to do:
cx.baseVal.value
<!DOCTYPE html> <html> <body> <svg xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="50" fill="red" id="cir"/> </svg> <script> console.log(document.getElementById("cir").cx.baseVal.value); console.log(document.getElementById("cir").cy.baseVal.value); </script> </body> </html>
Use console.log()
instead of Console.log()
console
is defined by the browser, Console
is not (JS, as most languages, is case-sensitive)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.