I wanted to the position of the embedded iframe to relatively position certain elements in the parent DOM. I tried this out.
var iframe_posy = $('iframe').css('top');
var iframe_posx = $('iframe').css('left');
<iframe src="game/game.html" style="border: 0; width: 100%; height: 600px;">...</iframe>
When I log iframe_posx and iframe_posy, I get ‘undefined’. Anything that I am missing?
Thanks!
Assuming you’re using jQuery, use position() , that is,
$('iframe').position().leftand$('iframe').position().top