Sometimes, we want to get right position of an element with JavaScript.
In this article, we’ll look at how to get right position of an element with JavaScript.
How to get right position of an element with JavaScript?
To get right position of an element with JavaScript, we can use the style.right
property.
For instance, we write:
<div style='position: relative; right: 50px'>
hello world
</div>
to add an element with the right position set.
Then we write:
const div = document.querySelector('div')
console.log(div.style.right)
to get select the div with querySelector
.
Then we use div.style.right
to get the right position.
Therefore, we see '50px'
logged.
Conclusion
To get right position of an element with JavaScript, we can use the style.right
property.