I'm working on a script (extension) that selects an HTML tag and does some stuff to it. However, this HTML tag will dynamically load up on the page at some given time, and I want to detect it as soon as it loads. Currently I am polling the html page in a while loop (checking for undefined) but it is lagging the page a lot. Is there a workaround?
$(document).ready(function() {
  // some code
  var sizesList=document.getElementsByClassName("exp-pdp-size-dropdown-container nsg-form--drop-down--option-container selectBox-options nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown-menu")[0];
  while(typeof(sizesList) == 'undefined') {
    setTimeout(function() {}, 700)
    sizesList=document.getElementsByClassName("exp-pdp-size-dropdown-container nsg-form--drop-down--option-container selectBox-options nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown-menu")[0];
  }
// some more code
}
I'm testing it on this webpage.
 
    