I'm simply trying to get the top, left, etc position of an element when in the admin backend...
function my_backend_assets() {
wp_enqueue_script(
'my-editor-js',
plugins_url( '/src/editor.js', dirname( __FILE__ ) ),
array( 'jquery' ),
filemtime( plugin_dir_path( __FILE__ ) . '/src/editor.js' )
);
}
add_action( 'admin_enqueue_scripts', 'my_backend_assets', 99999 );
And my js
$( document ).load(function() {
var $test = $(".my-div").offset();
console.log( $test.top );
});
I get Uncaught TypeError: Cannot read property 'left' of undefined
Element my-div exists. I can log it it fine. The script loads in the backend. Jquery works... I don't understand why I can't get the offest() of elements.
More details:
I'm loading my custom js in the Wordpress edit page (when eidting a page)
I'm trying to get the offset of any UI element within the editor page. For example the editor text area. It is not returning anything. Only with a timeout function it works.
I am using the latest Wordpress which has the Gutenberg editor.