Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6889599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:10:36+00:00 2026-05-27T06:10:36+00:00

function prepareEventHandlers() { var sectionButton1 = document.getElementById(sectionButton1); var sectionButton2 = document.getElementById(sectionButton2); var sectionButton3 =

  • 0
function prepareEventHandlers() {
    var sectionButton1 = document.getElementById("sectionButton1");
    var sectionButton2 = document.getElementById("sectionButton2");
    var sectionButton3 = document.getElementById("sectionButton3");
    var sectionButton4 = document.getElementById("sectionButton4");
    var sectionButton5 = document.getElementById("sectionButton5");

    var enabled1 = true;
    var enabled2 = false;
    var enabled3 = false;
    var enabled4 = false;
    var enabled5 = false;


    function checkEnabled() {
        if (enabled1) {
            sectionButton1.setAttribute("class", "sectionButtonEnabled");
        }
        if (enabled2) {
            sectionButton2.setAttribute("class", "sectionButtonEnabled");
        }
        if (enabled3) {
            sectionButton3.setAttribute("class", "sectionButtonEnabled");
        }
        if (enabled4) {
            sectionButton4.setAttribute("class", "sectionButtonEnabled");
        }
        if (enabled5) {
            sectionButton5.setAttribute("class", "sectionButtonEnabled");
        }

    }

    checkEnabled();
    sectionButton1.onmouseover = function() {
        if (enabled1) {
            sectionButton1.setAttribute("class", "sectionButtonOver");
        }
    };
    sectionButton1.onmouseout = function() {
        if (enabled1) {
            sectionButton1.setAttribute("class", "sectionButtonEnabled");
        }
    };
    sectionButton2.onmouseover = function() {
        if (enabled2) {
            sectionButton2.setAttribute("class", "sectionButtonOver");
        }
    };
    sectionButton2.onmouseout = function() {
        if (enabled2) {
            sectionButton2.setAttribute("class", "sectionButtonEnabled");
        }
    };
    sectionButton3.onmouseover = function() {
        if (enabled3) {
            sectionButton3.setAttribute("class", "sectionButtonOver");
        }
    };
    sectionButton3.onmouseout = function() {
        if (enabled3) {
            sectionButton3.setAttribute("class", "sectionButtonEnabled");
        }
    };
    sectionButton4.onmouseover = function() {
        if (enabled4) {
            sectionButton4.setAttribute("class", "sectionButtonOver");
        }
    };
    sectionButton4.onmouseout = function() {
        if (enabled4) {
            sectionButton4.setAttribute("class", "sectionButtonEnabled");
        }
    };
    sectionButton5.onmouseover = function() {
        if (enabled5) {
            sectionButton5.setAttribute("class", "sectionButtonOver");
        }
    };
    sectionButton5.onmouseout = function() {
        if (enabled5) {
            sectionButton5.setAttribute("class", "sectionButtonEnabled");
        }
    };
}


window.onload = function() {
    prepareEventHandlers();
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:10:37+00:00Added an answer on May 27, 2026 at 6:10 am

    Anytime you find yourself writing variable names like “foo1”, “foo2”, etc, and they all do more or less the same thing, you really need to stop, back up, and declare an array.

    function prepareEventHandlers() {
        var sectionButtons = [];
        for (var i = 1; i <= 5; ++i)
          sectionButtons[i] = document.getElementById('sectionButton' + i);
    
        var enabled = [ true, false, false, false, false ];
    
        function checkEnabled() {
            for (var i = 1; i <= 5; ++i)
              if (enabled[i]) sectionButtons[i].className = 'sectionButtonEnabled';
        }
    
        checkEnabled();
    
        for (i = 1; i <= 5; ++i) {
          sectionButton[i].onmouseover = function(i) {
            return function() {
              if (enabled[i]) sectionButton[i].className = 'sectionButtonOver');
            }
          }(i);
          sectionButton[i].onmouseout = function(i) {
            return function() {
              if (enabled[i]) sectionButton[i].className = 'sectionButtonEnabled';
          }(i);
        }
    }
    
    
    window.onload = function() {
        prepareEventHandlers();
    };
    

    Now, two other things:

    1. Don’t set the “class” attribute with “setAttribute()”. Instead, manipulate the “className” property of the DOM element.
    2. Instead of setting the class directly to those strings, it’s better to construct your own “addClass()” and “removeClass()” functions. Keep in mind that the class can be a list of class names, separated by spaces. Such functions would look something like this:

      function addClass(elem, c) {
        elem.className += ' ' + c;
      }
      
      function removeClass(elem, c) {
        elem.className = elem.className.replace(new RegExp('\\b' + c + '\\b', 'g'), ''));
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function check(id){ var _id = document.getElementById(id); url = test.php?check=1&id= + _id; } i want
function getUsername() { var userName = document.form.screen_name.value; document.getElementById(display).innerHTML = userName; var apiName = https://api.twitter.com/1/users/lookup.json?screen_name=
function ExChgClsName(Obj,NameA,NameB){ var Obj=document.getElementById(Obj)?document.getElementById(Obj):Obj; Obj.className=Obj.className==NameA?NameB:NameA; } <a href=javascript:showMenu(2);> i am a newbie of the
function checkauth(){ jQuery.getJSON(/users/checkauthjson, null, function(xhr){ if(xhr.success){ return true;}else{ return false;} }); } Obviously, that
function test() { var flag1 = false; if ($('#field1').attr('value') || !$('#field1').attr('value')) { $.ajaxSetup({ cache:
function validateRequiredFields(formid) { var inputs = document.getElementsByClassName('required'); for(i=0;i<inputs.length;i++) { var FieldID = inputs[i].id; if(
function moveto(step1, step2, step3) { var w = $(document).width(); var h = $(document).height(); $('#full').animate({
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _
function register_contact ($person = array()) { $nogood = false; foreach ($person as $val) {
(function($) { $.fn.myPlugin = function(options) { var _this; var timer1; var foo = function(n)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.