<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Javascript in a Wordpress site doesn&#x27;t work]]></title><description><![CDATA[<p dir="auto">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?</p>
<p dir="auto">This is my Javascript code:</p>
<pre><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) =&gt; {
        // Get the country class (assumes it's the first class in the classList)
        let rowCountryClass = Array.from(row.classList).find(cls =&gt; 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);
        }
    });
});
</code></pre>
<p dir="auto">And this is the code I inserted in my functions.php file to include it:</p>
<pre><code>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');
</code></pre>
<p dir="auto">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.</p>
]]></description><link>https://forums.opera.com/topic/73138/javascript-in-a-wordpress-site-doesn-t-work</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 09:44:58 GMT</lastBuildDate><atom:link href="https://forums.opera.com/topic/73138.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Jul 2024 20:27:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 18:25:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/122">@burnout426</a> I just opened a private window, and it looks the same to me - The rows Alabama through Delaware are all white.</p>
<p dir="auto">I'll have to wait until someone with Opera on a Mac can check it out. If it's just a problem on my laptop, then I can continue using the Javascript, though I'll have to test it in Safari.</p>
<p dir="auto">I've been getting lots of great scripts from ChatGPT, but half of them don't work because of weird bugs (firewalls, services not enabled, or whatever) in WordPress or my host (SiteGround). Then there are the caching problems, which are another pain.</p>
<p dir="auto">Thanks for the input.</p>
]]></description><link>https://forums.opera.com/post/356794</link><guid isPermaLink="true">https://forums.opera.com/post/356794</guid><dc:creator><![CDATA[Geobop]]></dc:creator><pubDate>Tue, 30 Jul 2024 18:25:24 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 17:43:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/823158">@geobop</a> I'm only able to test on Windows 11 and not macOS, but for what it's worth, the page looks the same in Chrome, Firefox and Opera. The <em>groups</em> alternate between gray and white just as you described in Opera just like they do in other browers.</p>
<p dir="auto">Maybe it's a macOS-only issue with Opera or it's something messed up with your Opera. How does the page look to you in a private window in Opera?</p>
]]></description><link>https://forums.opera.com/post/356786</link><guid isPermaLink="true">https://forums.opera.com/post/356786</guid><dc:creator><![CDATA[burnout426]]></dc:creator><pubDate>Tue, 30 Jul 2024 17:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 12:49:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/122">@burnout426</a> <a href="https://symbols.geobop.com/resources/national-symbols/north-america-symbols/usa-symbols/usa-flowers/" target="_blank" rel="noopener noreferrer nofollow ugc">https://symbols.geobop.com/resources/national-symbols/north-america-symbols/usa-symbols/usa-flowers/</a></p>
<p dir="auto">I started out with a simple CSS style that gives even-numbered rows a gray background. However, there are some states that are represented by two or three rows. I wanted to make every row representing a particular state the same color.</p>
<p dir="auto">So, the Javascript groups pages with the same class (e.g. w-al for Alabama) together, counting them as a single row. I inserted these classes in Alabama through Delaware, which look fine in Safari.</p>
<p dir="auto">The rest of the rows still have the original class="tr--even." They look fine in Opera but are all gray in Safari.</p>
<p dir="auto">Thank you.</p>
]]></description><link>https://forums.opera.com/post/356770</link><guid isPermaLink="true">https://forums.opera.com/post/356770</guid><dc:creator><![CDATA[Geobop]]></dc:creator><pubDate>Tue, 30 Jul 2024 12:49:42 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 11:24:04 GMT]]></title><description><![CDATA[<p dir="auto">Link to the page and description of what exactly is supposed to work but doesn't?</p>
]]></description><link>https://forums.opera.com/post/356766</link><guid isPermaLink="true">https://forums.opera.com/post/356766</guid><dc:creator><![CDATA[burnout426]]></dc:creator><pubDate>Tue, 30 Jul 2024 11:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 11:16:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/823158">@geobop</a> OK, Chrome is a browser based on Chromium.</p>
]]></description><link>https://forums.opera.com/post/356758</link><guid isPermaLink="true">https://forums.opera.com/post/356758</guid><dc:creator><![CDATA[leocg]]></dc:creator><pubDate>Tue, 30 Jul 2024 11:16:31 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 08:45:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/823158">@geobop</a> Are you on the latest opera, and are you using any add-ons?</p>
]]></description><link>https://forums.opera.com/post/356755</link><guid isPermaLink="true">https://forums.opera.com/post/356755</guid><dc:creator><![CDATA[jenster99]]></dc:creator><pubDate>Tue, 30 Jul 2024 08:45:29 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Tue, 30 Jul 2024 06:31:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/73">@leocg</a> I don't know what Chromium-based means. However, I tried it in Firefox and Google Chrome just now, and it works in both of them.</p>
<p dir="auto">I recently bought a new laptop and hadn't got around to installing any browsers yet. Opera is my default browser, and I have a Mac, so it naturally has Safari.</p>
]]></description><link>https://forums.opera.com/post/356749</link><guid isPermaLink="true">https://forums.opera.com/post/356749</guid><dc:creator><![CDATA[Geobop]]></dc:creator><pubDate>Tue, 30 Jul 2024 06:31:50 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript in a Wordpress site doesn&#x27;t work on Mon, 29 Jul 2024 22:50:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/823158">@geobop</a> Does it work in other Chromium based browsers?</p>
]]></description><link>https://forums.opera.com/post/356734</link><guid isPermaLink="true">https://forums.opera.com/post/356734</guid><dc:creator><![CDATA[leocg]]></dc:creator><pubDate>Mon, 29 Jul 2024 22:50:22 GMT</pubDate></item></channel></rss>