1
I have the following piece of code:
var cta = document.querySelector('.cta');
In Chrome/Opera it returns the element correctly, only in Firefox it is returned me the error :
TypeError: cta is null
Does anyone know what it can be?
I’m calling him via:
window.addEventListener('load', () => {
cta.style.opacity = 1;
});
Complete code:
var cta = document.querySelector('.cta');
function box() {
if(cta) {
var vitrine = [].slice.call(document.querySelectorAll('.vitrine'));
for(var i = 0; i < vitrine.length; i++) {
vitrine[i].style.height = window.getComputedStyle(vitrine[i]).width;
}
}
}
box();
window.addEventListener('load', () => {
cta.style.opacity = 1;
});
window.addEventListener('resize', () => box());
Can you make an example working here or in jsFiddle? What happens if
var cta = document.querySelector('.cta');
is also inside thatload
?– Sergio
What is version of your Firefox? I have tested now in version 47.0.2 is worked correctly. In the Mozilla documentation itself https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector it is possible to find that the Mozilla supports querySelector
– Edvaldo Farias
You could put in a bigger piece of code so we can analyze it better?
– Edvaldo Farias
It would be very difficult to put in jsFiddle and yes really if I put this piece of code in Firefox it works, I will update the question with the full code.
– dsantoro