html - More efficient way to change styles using Javascript? -


i have section, i've split multiple sections loaded javascript easier reading. i'd side navigation have different background color if both hovered on , if 1 selected, , have border right unique color each option. have working no problems, i'm wondering if there more efficient way way am.

in nutshell, html:

<nav>                <p id="bout" onclick="bout()">about us</p>             <p id="mish" onclick="mish()">our mission</p>             <p id="team" onclick="team()">the team</p>             <p id="how" onclick="how()">how works</p>             <p id="poli" onclick="poli()">policies</p>         </nav>          <div class="actual">              <div id="about">             <h2>about us</h2>             <p>we conglomerate of hoodlums.</p>             </div>          </div><!-- end actual --> 

and js:

function bout() {     document.getelementbyid("about").innerhtml= '<h2>about us</h2><p>we conglomerate of hoodlums.</p>';     document.getelementbyid("bout").style.borderright='3px solid red';     document.getelementbyid("mish").style.borderright='none';     document.getelementbyid("team").style.borderright='none';     document.getelementbyid("how").style.borderright='none';     document.getelementbyid("poli").style.borderright='none';      document.getelementbyid("bout").style.backgroundcolor='ghostwhite';     document.getelementbyid("mish").style.backgroundcolor='bisque';     document.getelementbyid("team").style.backgroundcolor='bisque';     document.getelementbyid("how").style.backgroundcolor='bisque';     document.getelementbyid("poli").style.backgroundcolor='bisque';  }  function mish() {     document.getelementbyid("about").innerhtml = '<h2>mission</h2><p>our mission rid world of dust bunnies.</p>';     document.getelementbyid("bout").style.borderright='none';     document.getelementbyid("mish").style.borderright='3px solid orange';     document.getelementbyid("team").style.borderright='none';     document.getelementbyid("how").style.borderright='none';     document.getelementbyid("poli").style.borderright='none';      document.getelementbyid("bout").style.backgroundcolor='bisque';     document.getelementbyid("mish").style.backgroundcolor='ghostwhite';     document.getelementbyid("team").style.backgroundcolor='bisque';     document.getelementbyid("how").style.backgroundcolor='bisque';     document.getelementbyid("poli").style.backgroundcolor='bisque'; } 

as can see, it's quite cumbersome have explicitly turn off on each style when clicked. main key though have each border-right different color.

here jsfiddle whole thing, reason it's not acknowledging js: http://jsfiddle.net/4crhd/

additional random question: possible link page different piece of content loaded about, example, can link page "mish()" loaded instead of whats in html?

the best way use css. add remove class on parent element , have css apply right rules.

body.mish #bout{    border-right : 3px solid red, }  body.bout #bout{    border-right : 3px solid blue, } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -