skip to Main Content

I’m working on a JavaScript script that aims to add some events on a couple of buttons in the barcode interface in Odoo V15.

When I’m trying to add an event on a button in the standard navbar at the top of the page (the navbar that allows, for example, to go back to the applications list) I can’t locate the button with jQuery. I select the button through its class, but the returned object remains empty.I’m simply doing something like :

console.log($('.buttonClass'));

I guess that is because my script executes before the button generation.
I tried to place my script at the last position of the assets in the manifest, but it still not working.

How could I execute JavaScript code only when my page is fully loaded, so I can be sure that all of my elements exist?

Thank you,
Regards,

2

Answers


  1. Try to use the DOMContentLoaded event for all your script.

    More here: https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event

    Example:

    addEventListener('DOMContentLoaded', (event) => {
      // your code
      console.log($('.buttonClass'));
    });
    Login or Signup to reply.
  2. How about using $(document).ready()?

    Example:

    $(document).ready(function() {
        console.log($('.buttonClass'));
    });

    See more about ready on jQuery API Documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search