Javascript Dojo.query() retrieves objects that are from the previous page

0
I'm running into an issue where i'm using a mendix layout with a HTMLSnippet containing javascript only. This javascript is looking to find certain classes within my DOM for styling purposes. For this i use dojo.query. The whole snippet is triggered with domReady! When triggered the first time, this snippet works fine. Once i switch between pages. I also get DOM elements found by the query method from the previous page. Where they aren't anywhere to be found in my current page. Does anyone know how i can prevent this from happening in a snippet?  
asked
1 answers
7

Mendix executes the widgets before the page is loaded, so if you're using functions that manipulate HTML outside of the widget itself this can happen. Since Mx 6.7 there is an onNavigation event you can use to know that the new page is loaded:

this.connect(this.mxform, "onNavigation", function() {
  // custom logic
});

if you put your logic there, it will only be executed after the new page has been loaded.

 

Documentation: https://apidocs.mendix.com/7/client/mxui_lib_form__FormBase.html

answered