Reputation: 1767
I've got a fixed pixel positioned div element that I'd like to take its size and position and convert into relative percentage. How would you do that?
Upvotes: 0
Views: 280
Reputation: 6725
You want to use parentNode to access the parent, compare their sizes and voila.
var foo = document.getElementById('foo');
var bar = document.getElementById('foo').parentNode;
console.log('Width: ' + (foo.offsetWidth / bar.offsetWidth) + '%')
Upvotes: 1