Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><code>&lt;header&gt;</code> isn't an element, but <code>&lt;head&gt;</code> is.</li> <li>the only legal children of <code>&lt;html&gt;</code> are <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code>. The sample code has a <code>&lt;script&gt;</code> element that's a child of <code>&lt;html&gt;</code></li> <li><code>nav_color_swap</code> sets the classname for navid, rather than <code>navid_array[i]</code>, when <code>navid != navid_array[i]</code>. This is likely the source of your problem.</li> <li>When that's fixed, the click handlers for the <code>&lt;a&gt;</code> will set the class name for all elements to "navCSS1", since the <code>&lt;a&gt;</code> don't have ID attributes.</li> </ul> <p>Since at most two element classes will need to change with each click, I recommend keeping track of the current element rather than looping over all elements:</p> <pre><code>&lt;style type="text/css"&gt; .selected { background-image:url('news_selected.png'); } .news, .news li { padding: 0; margin: 0; list-style-type: none; } ... &lt;/style&gt; &lt;script type="text/javascript"&gt; function createNavSelector(curr_nav, selectedClass, unselectedClass) { return function (nav) { curr_nav.className = unselectedClass; curr_nav = nav; curr_nav.className = selectedClass; } }; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; ... &lt;div class="container_news"&gt; &lt;ul class="news"&gt; &lt;li id="nav1" onclick="nav_select(this)"&gt;Blah 1&lt;/li&gt; &lt;li id="nav2" onclick="nav_select(this)"&gt;Blah 2&lt;/li&gt; &lt;li id="nav3" class="selected" onclick="nav_select(this)"&gt;Blah 3&lt;/li&gt; &lt;li id="nav4" onclick="nav_select(this)"&gt;Blah 4&lt;/li&gt; &lt;li id="nav5" onclick="nav_select(this)"&gt;Blah 5&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var nav_select = createNavSelector(document.getElementById('nav3'), 'selected', ''); </code></pre> <p>Since the <code>#nav*</code> appear to be a list of news items or a list of navigation items, I switched to using elements, since they carry more semantic information than <code>&lt;div&gt;</code>s. At this point, div-vs-ol/ul is largely a matter of personal preference. </p> <p>I also renamed functions and element classes to reflect their purpose, rather than how they fulfill that purpose. That way, you can change their behavior without requiring a change in name.</p> <p>Did you use the <code>&lt;a&gt;</code> to support old versions of IE? I wouldn't worry about anything older than <a href="http://www.google.com/search?q=browser+statistics" rel="nofollow noreferrer">IE 6</a>.</p> <hr> <p>As per No Refund, No Return's comment, here's some links to get you started on debugging JS using <a href="http://getfirebug.com/" rel="nofollow noreferrer">Firebug</a>. Safari also has a good debugger, if that's your browser of choice.</p> <ul> <li><a href="http://www.evotech.net/blog/2007/06/introduction-to-firebug/" rel="nofollow noreferrer">Intro to Firebug</a></li> <li><a href="http://www.webmonkey.com/tutorial/Build_Better_Pages_With_Firebug" rel="nofollow noreferrer">Build Better Pages With Firebug</a></li> <li><a href="http://www.digitalmediaminute.com/screencast/firebug-js/" rel="nofollow noreferrer">Guite to JS Debugging using Firebug</a> (video)</li> </ul>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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