Saturday, 29 December 2018

WordPress Jquery cannot read property for offset in admin backend

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.



from WordPress Jquery cannot read property for offset in admin backend

No comments:

Post a Comment