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

  • SEARCH
  • Home
  • 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 6724721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:43:24+00:00 2026-05-26T09:43:24+00:00

So I have a web app which uses all the hot keys from A

  • 0

So I have a web app which uses all the hot keys from A to Z.

Each hot key is used for a tab. So for example:

I have 20 tabs:

#tab1, #tab2, #tab3, #tab4 etc. All tabs get a class of .tabs.

So for the hotkeys to work I made this:

if (e.keyCode == 65) {$('.tabs:not(#tab1)').hide();$("#tab1").fadeIn();}
if (e.keyCode == 66) {$('.tabs:not(#tab2)').hide();$("#tab2").fadeIn();}
if (e.keyCode == 67) {$('.tabs:not(#tab3)').hide();$("#tab3").fadeIn();}
if (e.keyCode == 68) {$('.tabs:not(#tab4)').hide();$("#tab4").fadeIn();}
if (e.keyCode == 69) {$('.tabs:not(#tab5)').hide();$("#tab5").fadeIn();}
if (e.keyCode == 70) {$('.tabs:not(#tab6)').hide();$("#tab6").fadeIn();}
if (e.keyCode == 71) {$('.tabs:not(#tab7)').hide();$("#tab7").fadeIn();}
//etc till keycode 81 and tab20.

So, is there a better optimizing way to make this so it will be written in less characters? Since on each line I’m using twice the the same ID.

Edit/Note: Sorry, the actual tab ID’s are random names.

Thanks

  • 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-26T09:43:24+00:00Added an answer on May 26, 2026 at 9:43 am

    Something like this perhaps:

    if(e.keyCode >= 65 && e.keyCode <= 81) {
        var tab = e.keyCode - 65 + 1;
        $('.tabs:not(#tab' + tab + ')').hide();
        $('#tab' + tab).fadeIn();
    }
    

    I don’t see how keycode 81 is supposed to be tab20 though, wouldn’t that be tab17?


    Update: If your tab ids can be anything at all then just throw them in an array:

    var tab_ids = [ 'where', 'is', 'pancakes', 'house', ... ];
    if(e.keyCode >= 65 && e.keyCode <= 81) {
        var tab = tab_ids[e.keyCode - 65];
        $('.tabs:not(#' + tab + ')').hide();
        $('#' + tab).fadeIn();
    }
    

    If you also have gaps in they keycodes then use an object instead of an array:

    var tab_ids = { 65: 'where', 70: 'is', 72: 'pancakes', 73: 'house', ... };
    var tab     = tab_ids[e.keyCode];
    if(tab) {
        $('.tabs:not(#' + tab + ')').hide();
        $('#' + tab).fadeIn();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight web app which uses ASP.net Website administration tool for user
I have a simple ASP.NET web app which uses a WCF Client to talk
I have a .Net 4 web app that uses Windows authentication and all works
I have a web app which connects to a server using a TCP connection
I have a Flash web app which displays user submitted PNG files. Files are
Have an ASP.net web app which works fine for a few days, but then
I have a LAMP (PHP) web app which need to interface with programs on
The thing I have a web app (asp.net) which needs to have a feed.
I have a user profile page on my web app which has contact information.
I have written a web app in PHP which makes use of Ajax requests

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.