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 8830161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:00:28+00:00 2026-06-14T08:00:28+00:00

I was just wondering how i can make this code into one function instead

  • 0

I was just wondering how i can make this code into one function instead of rewriting it 6 times like i have below. I am horrible with this stuff. I am sure there is a way to do it i just have no idea. Any help would be great.

    (function() {
    $('.one').click(function() {
      $('.glennpage').show();
      $('.emmapage').hide();
      $('.brodiepage').hide();
      $('.laurenpage').hide();
      $('.mattpage').hide();
      $('.jeremypage').hide();
    });
  });
$(function() {
    $('.two').click(function() {
      $('.glennpage').hide();
      $('.emmapage').show();
      $('.brodiepage').hide();
      $('.laurenpage').hide();
      $('.mattpage').hide();
      $('.jeremypage').hide();
    });
});
$(function() {
    $('.three').click(function() {
      $('.glennpage').hide();
      $('.emmapage').hide();
      $('.brodiepage').show();
      $('.laurenpage').hide();
      $('.mattpage').hide();
      $('.jeremypage').hide();
    });
});
$(function() {
    $('.four').click(function() {
      $('.glennpage').hide();
      $('.emmapage').hide();
      $('.brodiepage').hide();
      $('.laurenpage').show();
      $('.mattpage').hide();
      $('.jeremypage').hide();
    });
});
$(function() {
    $('.five').click(function() {
      $('.glennpage').hide();
      $('.emmapage').hide();
      $('.brodiepage').hide();
      $('.laurenpage').hide();
      $('.mattpage').show();
      $('.jeremypage').hide();
    });
});
$(function() {
    $('.six').click(function() {
      $('.glennpage').hide();
      $('.emmapage').hide();
      $('.brodiepage').hide();
      $('.laurenpage').hide();
      $('.mattpage').hide();
      $('.jeremypage').show();
    });
});
  • 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-06-14T08:00:29+00:00Added an answer on June 14, 2026 at 8:00 am

    First off you have multiple document.ready functions,
    which can be combined into one.

    $(function() {
        $('.one').click(function() {
    
        });
        $('.two').click(function() {
    
        });
        $('.three').click(function() {
    
        });
        etc...
    });
    

    then as @Shivan Raptor mentions you can move show/hide code into one function.
    But the problem with @Shivan Raptor’s code function is that it is just
    hiding all your selected elements, which doesn’t seem to be what you are
    trying to do.
    Based on what you’ve got it looks like your are trying to do something like a set of tabs,
    where clicking on one shows a certain tab section, and hide all the others. Clicking the next tab shows its corresponding tab section, and hides all the others, etc…

    If that’s what you are going for I would suggest adding an ID to each of your html elements. So instead of doing this:

    <div class='glennpage'></div>
    <div class='emmapage'></div>
    <div class='brodiepage'></div>
    etc...
    

    do this: and add a class so you can easily select them all at once

    <div id='glennpage' class="tabContent"></div>
    <div id='emmapage' class="tabContent"></div>
    <div id='brodiepage' class="tabContent"></div>
    etc...
    

    then instead of using .one, .two, .three, etc.. on your button elements (or whatever element your triggers are), use a class that matches one of the id’s on one of your tabContent sections:

    <button class="glennpage"></button>
    <button class="emmapage"></button>
    <button class="brodiepage"></button>
    etc...
    

    now we can rewrite your jquery to something like this:

    $('.one','.two','.three','.four','.five','.six').click(function() {
        $('.tabContent').hide();
        $(this).find('#' + $(this).attr('id')).show();
    });
    

    now when you click on one of the buttons, the jquery will hide all elements with a class of .tabContent, which is all your sections, then it will look for an element with the corresponding id and show that one.
    hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
i m just wondering if we can do this with preg replace like if
Just wondering how I can make my app open automatically at login, but make
Just wondering how I can paste an object after I have selected it in
I am just wondering how i can get the error causing LoginUser function to
I'm just wondering how I can read a text file in php, I'd like
Simple question. Just wondering if this can be done without me having to enforce
I am wondering if something like this could be done(of course what I have
I was just wondering how I can get a single tap to undo the
I was just wondering how I can animate the jQuery form ui's div update

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.