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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:07:05+00:00 2026-06-01T22:07:05+00:00

I have created the following code to show and hide divs. This shows one

  • 0

I have created the following code to show and hide divs. This shows one div at a time and hides the others. This works on all browsers except Safari.

HTML

<div class="buttons">
    <a class="button" id="showdiv1">Div 1</a>
    <a class="button" id="showdiv2">Div 2</a>
    <a class="button" id="showdiv3">Div 3</a>
    <a class="button" id="showdiv4">Div 4</a>
</div>
<div id="div1">1</div>
<div id="div2" style="display:none;">2</div>
<div id="div3" style="display:none;">3</div>
<div id="div4" style="display:none;">4</div>

JQuery

$('#showdiv1').click( function () {
    $('div[id^=div]').hide();
    $('#div1').show();
});
$('#showdiv2').click( function () {
    $('div[id^=div]').hide();
    $('#div2').show();
});
$('#showdiv3').click( function () {
    $('div[id^=div]').hide();
    $('#div3').show();
});
$('#showdiv4').click( function () {
    $('div[id^=div]').hide();
    $('#div4').show();
});​

I am an absolute beginner and thought that Jquery would be the most elegant solution to showing multiple divs and it is! Except for Safari!

Any help would be great-fully received!

  • 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-01T22:07:06+00:00Added an answer on June 1, 2026 at 10:07 pm

    I would assume the problem with Safari is because it does not raise a click event on a elements which have no href attribute.

    Also, your code can be simplified. Try this instead:

    <div class="buttons">
        <a class="button" id="showdiv1" href="#div1">Div 1</a>
        <a class="button" id="showdiv2" href="#div2">Div 2</a>
        <a class="button" id="showdiv3" href="#div3">Div 3</a>
        <a class="button" id="showdiv4" href="#div4">Div 4</a>
    </div>
    <div id="div1" class="child">1</div>
    <div id="div2" class="child" style="display:none;">2</div>
    <div id="div3" class="child" style="display:none;">3</div>
    <div id="div4" class="child" style="display:none;">4</div>
    

    jQuery

    $(".button").click(function(e) {
        e.preventDefault();
        $(".child").hide();
        $($(this).attr("href")).show();
    });
    

    Notice the use of classes to group elements together so that you don’t have so much code repetition.

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

Sidebar

Related Questions

I have the following code: $('a.btn-slide').toggle(function() { $(#SliderDIV).slideDown(fast); $(this).text('Hide/Show'); }); Only in Firefox, when
I have the following code and whichever service is created last works(so my annotations
I have created a PHP code to echo the following div <div id=main_catsel> <select
I have the following code $(#nav-mail).mouseenter(function(){ $(#dropdown_mail).show(); }); $(#dropdown_mail,#nav-mail).mouseleave(function(){ $(#dropdown_mail).hide(); }); and I am
I have created an ExpandableListView with the following code: <ExpandableListView android:id=@+id/android:list android:layout_width=wrap_content android:layout_height=0dp android:layout_marginTop=5dp
I have created an alert view with two buttons using the following code: UIAlertView
I have a transparent BufferedImage created with the following code(not relevant how it is
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom alertdialog by the following code: AlertDialog.Builder builder; AlertDialog alertDialog;

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.