Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


Get element position in browser with JavaScript

If you use table cells as menu buttons and autosize them, this code finds the left position of element with id 'menubutton', and then places element with id 'menubody' to the same left position:

var mbtn = document.getElementById('menubutton').getBoundingClientRect();
var mbody = document.getElementById('menubody'); = mbtn.left+'px';

Or using jQuery

var newLeft = $('#menubutton').offset().left;
development/js/get_elem_pos.txt · Last modified: 2017/12/12 09:25 by tplecko