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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:18:17+00:00 2026-06-05T10:18:17+00:00

Task: On click of li navigation filter show and hide content with a transitional

  • 0

Task: On click of li navigation filter show and hide content with a transitional fadein fade out.

Problem I’m just guessing and checking on where to place this fadein//fadeout transition. Furthermore, I feel like my code is too inefficiency because I’m using 4 conditional statements. Would stack lead me in creating a solution to improve the overall logic of this script so I can just make a pretty transition :c?

LIVE CODE

jQuery Script

$(document).ready(function () {

//attach a single click listener on li elements
$('li.navCenter').on('click', function () {

    // get the id of the clicked li
    var id = $(this).attr('id');

    // match current id with string check then apply filter
    if (id == 'printInteract') {
        //reset all the boxes for muliple clicks 
        $(".box").find('.video, .print, .web').closest('.box').show();

        $(".box").find('.web, .video').closest('.box').hide();

        $(".box").find('.print').show();
    }

    if (id == 'webInteract') {
        $(".box").find('.video, .print, .web').closest('.box').show();
        $(".box").find('.print, .video').closest('.box').hide();
        $(".box").find('.web').show();
    }
    if (id == 'videoInteract') {
        $(".box").find('.video, .print, .web').closest('.box').show();
        $(".box").find('.print, .web').closest('.box').hide()
        $(".box").find('.video').show();
    }
    if (id == 'allInteract') {
        $(".box").find('.video, .print, .web').closest('.box').show();
    }



});

HTML Selected

<nav>
<ul class="navSpaces">
    <li id="allInteract" class="navCenter">
        <a id="activeAll" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>all</h3></div></a>
    </li>
    <li id="printInteract" class="navCenter">
        <a id="activePrint" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/print.gif" /><h3>print</h3></div></a>
    </li>
    <li id="videoInteract" class="navCenter">
        <a id="activeVideo" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/video.gif" /><h3>video</h3></div></a>
    </li>
    <li id="webInteract" class="navCenter">
        <a id="activeWeb" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/web.gif" /><h3>web</h3></div></a>
    </li>
</ul>

BOX HTML

<div class="box">
<h1 title="Light me up"></h1>
<div class="innerbox">
    <figure>
        <img src="" />
    </figure>
    <ul class="categorySelect">
        <li class="print"></li>
        <li class="video"></li>
        <li class="web"></li>
    </ul>
</div>

ps. Sorry for the newbie question

  • 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-05T10:18:19+00:00Added an answer on June 5, 2026 at 10:18 am

    You can simplify your code and add transitions like this:

    $(document).ready(function () {
        //attach a single click listener on li elements
        $('li.navCenter').on('click', function () {
            var all = $(".box").find('.video, .print, .web');
            var activeCls = "." + this.id.replace("Interact", "");
            if (activeCls == ".all") {
                all.closest('.box').show();
            } else {
                var active = $(".box").find(activeCls);
                active.closest('.box').show();
                all.not(active).closest('.box').hide();
            }
        });
    });
    

    When you have this working, you can substitute a jQuery transition of your choice for the .show() and .hide() calls.

    I have assumed that you want to hide/show the .box container for each item, but without seeing the real page HTML for the content you’re hiding and showing, I can’t be sure that’s what you want to do. Whatever you hide/show you will want to be consistent in both the hide() and the show() which your original code is not.

    When selecting a transition to use, you will need to use something that works well when removing/adding multiple items. fadeIn() and fadeOut() will probably not work well that way because when the item finally fades out, the remaining items will jump around. I’m not sure what will work best. Perhaps animating the width to zero.

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

Sidebar

Related Questions

How can I hide my VC# applications task bar button and show a system
I'm having a problem with a task similar to this one: click (translated) (the
Here’s my problem: I cancel a Task with a Click Event which works fine.
I have a task to show digital clock (with minutes precision) on HTML page
Hi I want to perform a task when I click a specific tab, let's
I had task in web solution as button when I click on the button
a notification pops up when I get a new task. On click on that
I'm just trying to add a double click event to a HTML5 Canvas element.
I'd like to start the 'Scheduled Task Wizard' from the click of a button
I'm trying following task: I know we can calla method on button click by

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.