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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:45:17+00:00 2026-06-06T05:45:17+00:00

I have found and customized this JQuery script, which displays different content when different

  • 0

I have found and customized this JQuery script, which displays different content when different links are pressed.

But, when the targetDiv is already visible, i would like the change effect to be fade, so it’s only slide effect when you open and close targetDiv.

Also, i can’t figure out why the content is visibly in about a half second on page load. Can i avoid that?

Here it is on JSFiddle: http://jsfiddle.net/XwN2L/179/

JQuery (newest version):

jQuery(function(){
    jQuery('.targetDiv').hide();

    jQuery('#close').click(function(){
              jQuery('.targetDiv').slideUp();
    });

        jQuery('.showSingle').click(function(){
              jQuery('.targetDiv').hide();
              jQuery('#div'+$(this).attr('target')).slideDown();
        });
});

HTML:

<div class="buttons">
<a  class="showSingle" target="1">Div 1</a>
<a  class="showSingle" target="2">Div 2</a>
<a  class="showSingle" target="4">Div 4</a>
<a id="close">Close</a>
</div>

<br><br><br><br>
Lorem Ipsum<br>

<div id="div1" class="targetDiv">
<iframe width="420" height="315" src="http://www.youtube.com/embed/c1_LON8Ib2o" frameborder="0" allowfullscreen></iframe>
</div>

<div id="div2" class="targetDiv">
<iframe width="420" height="315" src="http://www.youtube.com/embed/s4GbpG-PypM" frameborder="0" allowfullscreen></iframe>
</div>

<div id="div4" class="targetDiv">
<iframe width="560" height="315" src="http://www.youtube.com/embed/DHef3iAjxiM" frameborder="0" allowfullscreen></iframe>
</div>
Lorem Ipsum
  • 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-06T05:45:19+00:00Added an answer on June 6, 2026 at 5:45 am

    Working Demo http://jsfiddle.net/efgFL/2/

    Use is(':visible') link: http://api.jquery.com/visible-selector/

    For the second part the blah text is not in any container where the show/hide is happening thats why.

    Hope this helps,

    code

    jQuery(function(){
        jQuery('.targetDiv').hide();
    
        jQuery('#close').click(function(){
                  jQuery('.targetDiv').slideUp();
        });
    
            jQuery('.showSingle').click(function(){
                if( jQuery('.targetDiv').is(':visible')){
                    jQuery('.targetDiv').hide();
                   jQuery('#div'+$(this).attr('target')).fadeIn();
                }else{
                  jQuery('.targetDiv').hide();
                  jQuery('#div'+$(this).attr('target')).slideDown();
                }
            });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found some jQuery codes for show content with slide effect, but none
I have found already some similar discussion on this, but would like to investigate
I found this http://source.android.com/source/downloading.html but it seems to have so many steps has to
I have found many great answers to this from a year ago (when it
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I have found documentation on using custom icons for jQuery mobile buttons and how
I have a customized ListView like this: List<Journal_Database> values = localDatabase.getAllJournalNames(); ListView journalNames =
Not sure if this is possible in git (I haven't found it but I
I have a slightly customized version of the LabelFor() Html Helper found in the
So far i have found two ways of liking a category to a customized

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.