0

When I'm trying to add script to Elementor via "HTML Edit" element from Elementor, or in any field of Elementor when edit it's HTML, addEventListener doesn't work out of admin. So if you load edited page as admin, it's work, if you join as a guest sends error: "Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')". All elements are available, tried everything, doesn't work. Any options to add script?

 function count() {
    let percent = Math.round(Number(document.querySelectorAll(".form-control")[2].value)/100*35+Number(document.querySelectorAll(".form-control")[2].value));
    document.querySelectorAll(".form-control")[3].value = percent ;
    document.querySelectorAll(".form-control")[4].value = Math.round(percent*1.35);
}
document.querySelectorAll(".form-control")[2].addEventListener("input", count);
  • You can use `console.log(document.querySelectorAll(".form-control")[2])` to see if that element can be found. If not, your script probably executes before the whole `body` is loaded. – Kokodoko Aug 13 '22 at 10:03
  • Already did, error that can't be found. But script runs after body and also if you're an admin it's work. Tried to run script after page load, tried with plugins to add script in footer, added script right after form-control block, etc., it's should start after, but doesn't work – BackEndJavaLove Aug 13 '22 at 10:06
  • Does this answer your question? [a custom JS and CSS for slider works only for "admin" , i need it to work for all users (public users + admin)](https://stackoverflow.com/questions/63915204/a-custom-js-and-css-for-slider-works-only-for-admin-i-need-it-to-work-for-al) – GrafiCode Aug 13 '22 at 10:06
  • (basically, could be a caching problem) – GrafiCode Aug 13 '22 at 10:08
  • @GrafiCode I don't understand where this guy found custom file and other stuff he made, so no. If you know how to fix it, explain in detail – BackEndJavaLove Aug 13 '22 at 10:28

1 Answers1

0

How to wait until an element exists? + On admin panel there's an extra input, so I've got wrong values when not as admin and searched with querySelectorAll

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – jasie Aug 17 '22 at 10:57