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 6198493

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:00:45+00:00 2026-05-24T04:00:45+00:00

I have 8 links that all need to show a div on click. I

  • 0

I have 8 links that all need to show a div on click. I want only 1 div to show at a time so when click on a new link the div that is currently displayed gets hidden and a new one gets displayed. So far I have a jQuery solution that works but it’s ugly. Is there an easier/more correct way to accomplish what I want?

<div>
<a href="#" class="link">Click Link</a><br />
<a href="#" class="link2">Click Link 2</a><br />
<a href="#" class="link3">Click Link 3</a><br />
<a href="#" class="link4">Click Link 4</a><br />
<a href="#" class="link5">Click Link 5</a><br />
<a href="#" class="link6">Click Link 6</a><br />
<a href="#" class="link7">Click Link 7</a><br />
<a href="#" class="link8">Click Link 8</a><br />
 <div class="testVid hideDiv" style="background:pink; height:200px">Test Vid Div<br /><br /><span class="close">CLOSE</span></div>
<div class="testVid2  hideDiv" style="background:pink; height:200px">Test Vid Div 2<br /><br /><span class="close2">CLOSE 2</span></div>
<div class="testVid3 hideDiv" style="background:pink; height:200px">Test Vid Div 3<br /><br /><span class="close3">CLOSE 3</span></div>
<div class="testVid4  hideDiv" style="background:pink; height:200px">Test Vid Div 4<br /><br /><span class="close4">CLOSE 4</span></div>
<div class="testVid5 hideDiv" style="background:pink; height:200px">Test Vid Div 5<br /><br /><span class="close5">CLOSE 5</span></div>
<div class="testVid6 hideDiv" style="background:pink; height:200px">Test Vid Div 6<br /><br /><span class="close6">CLOSE 6</span></div>
<div class="testVid7 hideDiv" style="background:pink; height:200px">Test Vid Div 7<br /><br /><span class="close7">CLOSE 7</span></div>
<div class="testVid8 hideDiv" style="background:pink; height:200px">Test Vid Div 8<br /><br /><span class="close8">CLOSE 8</span></div>

$(document).ready(function(){
    $("a.link").click(function(){
        $(".testVid").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close").click(function(){
        $(".testVid").hide();
        });

    $("a.link2").click(function(){
        $(".testVid2").show();
        $(".testVid").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close2").click(function(){
        $(".testVid2").hide();
        });

    $("a.link3").click(function(){
        $(".testVid3").show();
        $(".testVid2").hide();
        $(".testVid").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close3").click(function(){
        $(".testVid3").hide();
        });

    $("a.link4").click(function(){
        $(".testVid4").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close4").click(function(){
        $(".testVid4").hide();
        });

    $("a.link5").click(function(){
        $(".testVid5").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close5").click(function(){
        $(".testVid5").hide();
        })

    ;$("a.link6").click(function(){
        $(".testVid6").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid").hide();
        $(".testVid7").hide();
        $(".testVid8").hide();
    });
    $(".close6").click(function(){
        $(".testVid6").hide();
        });

    $("a.link7").click(function(){
        $(".testVid7").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid").hide();
        $(".testVid8").hide();
    });
    $(".close7").click(function(){
        $(".testVid7").hide();
        });

    $("a.link8").click(function(){
        $(".testVid8").show();
        $(".testVid2").hide();
        $(".testVid3").hide();
        $(".testVid4").hide();
        $(".testVid5").hide();
        $(".testVid6").hide();
        $(".testVid7").hide();
        $(".testVid").hide();
    });
    $(".close8").click(function(){
        $(".testVid8").hide();
        });
    $(".hideDiv").css('display', 'none');
});

Fiddle Here

  • 0 0 Answers
  • 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

Sidebar

Related Questions

I have 8 links that all need to show a div on click. I
I have a few links on my site that will need to show a
So I have these lines of javascript code that I need to remove all
Change all links that have an image in it to: javascript(alert(thehref)); eg. <a href=/galleries/anna-leah-111827/image01.html><img
I have a page with a few links that are all like this: <a
I want to match all lines that have any uppercase characters in them but
I have a logo link that's using a background-image (css sprite). All works fine,
I have links like these that I want to change: mypage.com?page=missions&id=5 mypage.com?page=hello I tried
I have an unordered list of 50 items. I want to show only 10
I have this jquery: $('.tbl-link').click(function(){ $('.tbl-content').animate({ opacity: 'show', //height: '+=300px', marginTop: '330px' }, 1200).css({

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.