Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"Leistungen" has the class lmark, while "Impressum" has imark. Your Javascript function for lmark-classed elements resets the background for all other lmark-classed elements, but not for the imark-classed ones. Same for the function that concerns imark.</p> <p>If you need to have only one non-default background for all lmark <em>and</em> imark elements, a correct (probably correct, though not tested) code is:</p> <pre><code>function li_mark(cell) { var elts=document.getElementById("up").getElementsByTagName("li"); //store the elements we need in a local variable so we don't have to rewrite all that line (and the browser won't have to do the fetching job again), we don't care if they're L-type or I-type for(var i in elts) if(elts[i].className &amp;&amp; elts[i].className.length&gt;=8) //check if there is a className and it is at least as long as "uplink-X", otherwise we don't process the element and skip to the next elts[i].className="uplink-"+elts[i].className.charAt(7); //we retrieve the letter for the type of class (L or I), and we append it to "upload-" to redefine the class of the current element cell.className+="-active"; //after the loop, all elements have their default class, so we just need to append "-active" to the one we want to be active } </code></pre> <p>Then, all your calls to <code>l_mark(this)</code> and <code>i_mark(this)</code> should simply be replaced by calls to <code>li_mark(this)</code>.</p> <p>P.S.: not related, but my current browser (Firefox) doesn't seem to like the <code>window.onload=setActive;</code>, saying that "setActive is not defined"...</p> <p><strong>Edit according to comments</strong>, having seen your JS file (<code>scripttests.js</code>):</p> <p>You still need 2 functions, <code>mark()</code> and <code>li_mark()</code>, because for <code>mark()</code> your active class is of the form <code>&lt;className&gt;active</code> instead of <code>&lt;className&gt;-X-active</code> (not the same pattern in naming the classes, and no need to retrieve the character Lor I).</p> <p>Another part of the problem is that you call <code>cell.className+="-active"</code> twice on the same cell in the one function you have.</p> <p>The last part of the problem is that you forgot the instruction within the <code>if</code> of the second loop: as there are no block brackets, the instruction that is executed when this <code>if</code> is true is <code>cell.className+="-active"</code>... executed as many times as the loop runs and the <code>if</code> is true.</p> <p>A (probably) working version would be:</p> <pre><code>function li_mark(cell) { var elts=document.getElementById("up").getElementsByTagName("li"); //store the elements we need in a local variable so we don't have to rewrite all that line (and the browser won't have to do the fetching job again), we don't care if they're L-type or I-type for(var i in elts) if(elts[i].className &amp;&amp; elts[i].className.length&gt;=8) //check if there is a className and it is at least as long as "uplink-X", otherwise we don't process the element and skip to the next elts[i].className="uplink-"+elts[i].className.charAt(7); //we retrieve the letter for the type of class (L or I), and we append it to "upload-" to redefine the class of the current element if(cell &amp;&amp; cell.className &amp;&amp; cell.className.length&gt;=8) { //if we passed an argument, then it must be a cell to activate, with a basic check on its className cell.className+="-active"; //after the loop, all elements have their default class, so we just need to append "-active" to the one we want to be active mark(); //we call mark() with no argument to reset all the items managed by mark(), we call it in this if-block to avoid infinite recursion } } function mark(cell) { var elts=document.getElementById("nav").getElementsByTagName("li"); //store the elements we need in a local variable so we don't have to rewrite all that line (and the browser won't have to do the fetching job again), we don't care if they're L-type or I-type for(var i in elts) if(elts[i].className) //check if there is a className, otherwise we don't process the element and skip to the next elts[i].className="link"; //we set back to the default class if(cell &amp;&amp; cell.className) { //if we passed an argument, then it must be a cell to activate cell.className+="active"; //after the loop, all elements have their default class, so we just need to append "active" to the one we want to be active li_mark(); //we call li_mark() with no argument to reset all the items managed by li_mark(), we call it in this if-block to avoid infinite recursion } } </code></pre>
    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