I can print this in the console. This is the link
document.getElementsByClassName('flip-card-back')[0].innerHTML
But when I'm doing the same in the JS (in an extension in firefox) this doesn't work.
console.log(document.getElementsByClassName('flip-card-back')[0].innerHTML)
window.addEventListener('load', function () {
var eles = document.getElementsByClassName('flip-card-back')[0].innerHTML;
console.log(eles);
})
What I'm doing wrong?
Edit: I've tried using MutationObserver.
According to the documentation of MutationOberserver I've tried using it.
// Select the node that will be observed for mutations
console.log('test');
const targetNode = document.getElementsByClassName('flip-card-back');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
// Use traditional 'for loops' for IE 11
for(const mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log('A child node has been added or removed.');
}
else if (mutation.type === 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
console.log('test2')
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Later, you can stop observing
observer.disconnect();
console.log('test3')
Test and test2 is printed but test3 is never printed, seems like it keep observing but never getting anything.