Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend CSS Class
    primarykey
    data
    text
    <p>I have a tab-styled navigation menu. My goal:</p> <ol> <li>Once the user mousovers tab X. add the "tabActive" class to tab X, if the tab already has the "tabActive" class, then remove it</li> <li>Show Div "X"</li> </ol> <p>I have the second part down, and my java code detects which tab is being hovered, but I can not get my additional class toggled correctly.</p> <p>My code so far:</p> <p><strong>HTML</strong></p> <pre><code>&lt;div id="subnav"&gt; &lt;div id="nav1" onmouseover="toggleDisplay('contentPayment')" class="Payment myNav"&gt; &lt;a href="#"&gt;Payment&lt;/a&gt;&lt;/div&gt; &lt;div id="nav2" onmouseover="toggleDisplay('content-shipping')" class="Shipping myNav"&gt; &lt;a href="#"&gt;Shipping&lt;/a&gt;&lt;/div&gt; &lt;div id="nav3" class="Warranty myNav"&gt; &lt;a href="#"&gt;Warranty&lt;/a&gt;&lt;/div&gt; &lt;div id="nav4" class="Feedback myNav"&gt; &lt;a href="#"&gt;Feedback&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>JAVASCRIPT</strong></p> <pre><code>&lt;script&gt; var divs = new Array(); divs.push("contentPayment"); divs.push("content-shipping"); function hasClass(element, cls) { return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') &gt; -1; } function toggleDisplay(id) { for (var i = 0; i &lt; divs.length; i++) { var item = document.getElementById(divs[i]); item.style.display = 'none'; } //Now use the passed ID to show the div you wanted to show var target = document.getElementById(id); target.style.display = 'block'; if (id == "contentPayment") { var CurrentTab = document.getElementById("nav1"); var AlreadyActive = hasClass("nav1", " tabActive"); if (AlreadyActive == true) { CurrentTab.className = "Payment myNav"; } else { CurrentTab.className += " " + "tabActive"; } } } &lt;/script&gt;​ </code></pre> <p>Any ideas what my problem is? I know jQuery would be <em>much</em> easier, but I am coding for eBay and they do not allow it. How do I get my tabActive class to toggle correctly?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload