0
I made a function to change a photo when an element is added in my table, table that I created a class to be able to change the photo, but to get the html element, I need to use querySelector, but I’m not getting with class, but when it is with id it will.
Ex.:
function teste() {
var elemento = document.querySelector('info-status');
var conteudo = elemento.textContent || elemento.innerText;
var teste = conteudo.length;
if (teste > 0) {
var img = document.getElementById('TrocaPost');
var imgg = document.getElementById('TrocaEntregue');
var image = document.getElementById('TrocaViagem');
img.src = 'caminhao/caminhaoCERTOazul.png';
imgg.src = 'caminhao/caminhaoCERTOazul.png';
image.src = 'caminhao/caminhaoCERTOazul.png';
}
}
the info-status
When it’s id, it takes, but when it’s class it doesn’t take.
Is there something wrong with my code or querySelector only takes ID?
document.querySelector('.class_nome');
anddocument.querySelector('#id_elemento');
, can you read that reply in the question Take elements by class/id with pure Javascript has some references.– NoobSaibot
Possible duplicate of Take elements by class/id with pure Javascript
– Jéf Bueno
It worked. Thank you!
– Maria