I added a Javascript function to a WordPress site, but I couldn't get it to work. Then I checked it in Safari and discovered that it is working. So why doesn't it work in Opera?
This is my Javascript code:
document.addEventListener("DOMContentLoaded", function() {
console.log("DOM fully loaded and parsed");
const tableRows = document.querySelectorAll('.table--symlist2 tbody tr');
console.log("Table rows:", tableRows);
let currentCountryClass = "";
let isOdd = true;
tableRows.forEach((row) => {
// Get the country class (assumes it's the first class in the classList)
let rowCountryClass = Array.from(row.classList).find(cls => cls.startsWith('w-'));
console.log("Current row country class:", rowCountryClass);
if (rowCountryClass !== currentCountryClass) {
// New country group
currentCountryClass = rowCountryClass;
isOdd = !isOdd; // Flip the isOdd flag for the new group
}
// Apply the appropriate class
if (isOdd) {
row.classList.add('odd');
console.log("Added 'odd' class to row:", row);
} else {
row.classList.add('even');
console.log("Added 'even' class to row:", row);
}
});
});
And this is the code I inserted in my functions.php file to include it:
function my_custom_scripts() {
wp_enqueue_script('custom-js', get_stylesheet_directory_uri() . '/custom.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_custom_scripts');
It looks like Javascript is enabled by default on Opera. In addition, I added this specific site for good measure, but it still doesn't work.