Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change your code from being called <code>onLoad</code> to be called <code>No wrap - in &lt;head&gt;</code>.</p> <p>Because the functions were inside the onLoad function scope and not the global scope, they were not readable and no javascript was being called when clicking the buttons.</p> <p>I didn't change any code, just the option on the left pane: <a href="http://jsfiddle.net/AAM7L/2/" rel="nofollow">jsFiddle</a></p> <h1>Update</h1> <p>You also had a small flaw in logic causing the classes to become intertwined. Here's what you were doing:</p> <blockquote> <p>When first object is clicked, set it's class to obj1_active. When second object is clicked set obj1's class to obj2 and set obj2's class to obj2_active.</p> </blockquote> <p>As you can see, we're crossing obj1 and obj2 classes. To solve this, we'll keep track of the last object clicked (<code>role</code>) and the class that it should be when a new object is clicked (<code>cname</code>).</p> <p>Here is the Demo: <a href="http://jsfiddle.net/AAM7L/9/" rel="nofollow">jsFiddle</a></p> <h2>Optimization</h2> <p>The code you have works, but it's not very optimized. We shouldn't need four different functions that all do essentially the same thing just to different elements.</p> <p>In this demo, I simply add and remove <code>_active</code> from the className of each element when clicked: <a href="http://jsfiddle.net/AAM7L/13/" rel="nofollow">jsFiddle</a></p> <p><strong>Lets take it a step further</strong> and use multiple classes. This is useful to be able to generalize our CSS declarations. Lets use the default classes, and only append the <code>active</code> class onto the active element and remove it when a new element is clicked.</p> <p>We'll also separate the <code>_</code> in the classNames so that <code>btn</code> is its own class as well as <code>mission</code>. This allows for us to really clean up our CSS code to improve readability as well as not need to update multiple sections when we just need a simple background color update or something of that nature.</p> <p>Here is the optimized demo: <a href="http://jsfiddle.net/AAM7L/11/" rel="nofollow">jsFiddle</a></p> <h3>Link Color</h3> <p>I'm not sure if you meant to do this, but you'll notice that the links sometimes start white then turn to black when clicked. This is because the <code>:link</code> pseudo selector only selects non-visited links. If you want it to select all links, then just use the <code>&lt;a&gt;</code> tag: <a href="http://jsfiddle.net/AAM7L/12/" rel="nofollow">Final jsFiddle</a></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.
    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