Categories
JavaScript Answers

How to get coordinates of an svg element with JavaScript?

Spread the love

Sometimes, we want to get coordinates of an svg element with JavaScript.

In this article, we’ll look at how to get coordinates of an svg element with JavaScript.

How to get coordinates of an svg element with JavaScript?

To get coordinates of an svg element with JavaScript, we call the getBoundingClientRect method.

For instance, we write

const { x, y } = element.getBoundingClientRect();

to get the x and y coordinates of the svg element with the getBoundingClientRect method.

Conclusion

To get coordinates of an svg element with JavaScript, we call the getBoundingClientRect method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

2 replies on “How to get coordinates of an svg element with JavaScript?”

Leave a Reply

Your email address will not be published. Required fields are marked *