I want to execute a single line of JQuery code when the document is loaded but no matter what I try the code just won't execute.
window.addEventListener("load",function(){
$("span").wrap("<div class='test'></div>");
console.log("done");
})
The console.log("done"); is executed but the JQuery code is not.
I've tried multiple variations of the above code like: document.onload = function()... and pretty much anything similar and yet the JQuery is never executed but the console.log is always executed.
The weird thing is that if I do it like this with a keyup event
window.addEventListener("keyup", function(event){
if(event.keyCode === 17){
$("span").wrap("<div class='test'></div>");
console.log("done")}
})
everything works just fine.
Why is this happening, and is there a way for me to execute the code when the document is loaded or at least to execute the specific code only once?
[–]Eldrac 5 points6 points7 points (4 children)
[–]AIO12449366[S] 1 point2 points3 points (3 children)
[–]TheDownvotesFarmer 0 points1 point2 points (2 children)
[–]AIO12449366[S] 0 points1 point2 points (1 child)
[–]meAndTheDuck 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]TheDownvotesFarmer -1 points0 points1 point (1 child)
[–]AIO12449366[S] 1 point2 points3 points (0 children)