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
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:
How about using
$(document).ready()
?Example:
See more about
ready
on jQuery API Documentation.