0
Why "addEventListener" and jQuery do not work in CODE PLAYGROUND?
I want that than I push "Enter button" in corresponding field corresponding "button" is clicking. First I tried to solve my problem by jQuery, but it does not work (it seems library don't connected). So I dicided to write my code on clear JavaScript, but have new problem "addEventListener" don't work. By the way code is working 100% in my browser, but in CODE PLAYGROUND it does not work. Here is the code: https://code.sololearn.com/WP1pKRRtfN2X/#html . Please help.
2 ответов
+ 3
Just wrap all your code from JS tab in a anonymized ( or not ) function assigned to the window.onload event:
window.onload = function() {
/* your code, at least initialization and start:
if you want to deal with Dom, you need to
wait for complete page loading */
};
The final semi-coma is requiring, as end an assignement.
Anyway, be careful of syntax of parameter to pass to the method getElementById; contrarly to the querySelector() method and to JQuery selector syntax, you must not put the '#' at start of the id... so, lines in your script as:
var enterNumbers = document.getElementById("#number");
... needs to be corrected ( or replaced with original JQuery call, as I suspect this was rest of your attempt to adapt it without JQuery?
0
Thank you. It helped. Also I found another my mistake. Now all working.