var simulateClick = function (elem) { // Create our event (with options) var evt = new MouseEvent('click', { bubbles: true, cancelable: true, view: window }); // If cancelled, don't dispatch our event var canceled = !elem.dispatchEvent(evt); }; function presetFilter() { simulateClick(document.getElementsByClassName('ubsf_filter-toggle')[0]); simulateClick(document.getElementsByClassName('ubsf_filters-select-checkbox')[0]); } var presetFilterInterval = setInterval(function() { if (Boolean(window.ubGoogleMapInstance)) { setTimeout(function() { presetFilter(); }, 50); clearInterval(presetFilterInterval); } }, 50);