1
I am running the following Javascript code on the site I made in Wordpress.
var itens = document.querySelectorAll('h1');
console.log(itens);
I am pulling a file that is in the js folder, but it does not bring back the items from H1, but if I run this same code above in the browser console it works. Can anyone tell me what I might be doing wrong?
I don’t know if it helps, but this is the browser console print => https://prnt.sc/les18p2
I believe the problem is in importing the file. Make sure that the file is being loaded. Updates the file by adding an Alert('test') and see if it has any results
– edson alves
Try putting the code inside this event:
document.addEventListener("DOMContentLoaded", function(){ CÓDIGO AQUI });
... may be running the code before loading the DOM.– Sam
Thanks @Sam worked out with the solution you talked about, you know tell me why this problem? is it a peculiarity of Wordpress?
– Randys Machado