Note that there are some explanatory texts on larger screens.

plurals
  1. POonClick javascript: navigation with changing css background images / two types
    primarykey
    data
    text
    <p>i am doing a site with 2 navigations (navs) including links, each of them in another div.</p> <p>When a link is clicked it should change its background image in the css (change class). And only one link of its class can change the background.</p> <p>In the second nav there is one link which is also included in nav 1. Also are in the second nav two different background images to "toggle".</p> <p>I already have accomplished the first nav, but I do not know how to include the second one. In the second one is the problem that two links should not change their background at the same time.</p> <p>The site: <a href="http://enlifer.de/test25/zp-kazachkova.html" rel="nofollow">http://enlifer.de/test25/zp-kazachkova.html</a></p> <p>The second nav is at the height of the logo. If "Leistungen" is clicked in the second nav, the first one should also change its default background and vice versa.</p> <p>Following code is relevant.</p> <p><strong>First nav</strong></p> <pre><code>&lt;navigation&gt; &lt;ul id="nav"&gt; &lt;li class="link" onclick="mark(this)"&gt; &lt;a href="#" class="textlink"&gt;Kontakt&lt;/a&gt; &lt;/li&gt; &lt;li class="link" onclick="mark(this)"&gt; &lt;a href="#" class="textlink"&gt;Anfahrt&lt;/a&gt; &lt;/li&gt; &lt;li class="link" onclick="mark(this)"&gt; &lt;a href="#" class="textlink"&gt;Leistungen&lt;/a&gt; &lt;/li&gt; &lt;li class="link" onclick="mark(this)"&gt; &lt;a href="#" class="textlink"&gt;Praxisteam&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/navigation&gt; </code></pre> <p><strong>Second nav</strong></p> <pre><code>&lt;up&gt; &lt;ul id="up"&gt; &lt;li class="uplink-l" onclick="l_mark(this)"&gt; &lt;a href="#" class="uptextlink-l"&gt;Leistungen&lt;/a&gt; &lt;/li&gt; &lt;li class="uplink-i" onclick="i_mark(this)"&gt; &lt;a href="#" class="uptextlink-i"&gt;Impressum&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/up&gt; </code></pre> <p><em><strong>JavaScript</em></strong></p> <pre><code>&lt;script type="text/javascript"&gt; function mark(cell) { for(i=0; i &lt; document.getElementById("nav").getElementsByTagName("li").length; i++) { document.getElementById("nav").getElementsByTagName("li")[i].className="link"; } cell.className="linkactive"; } function l_mark(cell) { for(i=0; i &lt; document.getElementById("up").getElementsByTagName("li")[0].length; i++) { document.getElementById("up").getElementsByTagName("li")[0][i].className="uplink-l"; } cell.className="uplink-l-active"; } function i_mark(cell) { for(i=0; i &lt; document.getElementById("up").getElementsByTagName("li")[1].length; i++) { document.getElementById("up").getElementsByTagName("li")[1][i].className="uplink-i"; } cell.className="uplink-i-active"; } window.onload = setActive; &lt;/script&gt; </code></pre> <p>Thanks!</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