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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:10:04+00:00 2026-06-04T11:10:04+00:00

For some reason the code is behaving strangely. This happens in the If Else

  • 0

For some reason the code is behaving strangely.
This happens in the If Else function. In the Else part, its supposed to fadeOut over 1000ms and then remove the Class and then go onto the next statement. But apparently the second statement gets called out first and it makes everything go bad . 🙁 .

$(function() {

$(document).click(function(e) {
    if((e.target.id == 'RWorld') || (e.target.id == 'abc'))
    { 
    $(".sborder").fadeOut(1000, function() {

    $(".sborder").removeClass("sborder");
    });
    }

});




$("div#inner").children().click(function() {


//$("div#inner .sborder").removeClass("sborder");

var name = $(this).attr('id');

//alert($("div#inner").find("div").hasClass("sborder"));
if($(".sub"+name).hasClass("sborder"))
{
    $(".sub"+name).fadeOut(300, function() {
    $(".sub"+name).removeClass("sborder");
    });
}
else
{



    $(".sborder").fadeOut(1000, function() { 
    $(".sborder").removeClass("sborder");});       // The Problem is in here. This piece of Code doesnt work exactly as i thought it would ...

    $(".sub"+name).addClass("sborder").fadeIn(1000);

}
});
});

Please help :(.

  • 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-04T11:10:05+00:00Added an answer on June 4, 2026 at 11:10 am

    You probably want the fadeIn to happen at the same time as the fadeout, correct? In that case you need to cache your query results like this:

    var $sborder = $(".sborder");
    $sborder.fadeOut(1000, function() {
        $sborder.removeClass("sborder");
    });
    $(".sub" + name).addClass("sborder").fadeIn(1000);
    

    Your problem was the removeClass(“sborder”) was removing the sborder class you added to $(“.sub” + name) because it was happening 1 second later. In other words the order things were happening was as follows:

    1. Start fading out what currently has a class of “sborder”
    2. Add class of “sborder” to $(“.sub” + name)
    3. Start fading in $(“.sub” + name)
    4. 1 second after item 1. started fading out remove the class of “sborder” from every element that now has a class of “sborder” which now includes every element returned by $(“.sub” + name) because of item 2.

    On a best practices note, when using jQuery…

    • Whenever possible, try to always drill down from something with an id or tagname ( $(‘#container .sborder’) ). Searching by class can be very slow in older browsers and adding some context means that jQuery doesn’t have to search through your entire document.
    • Whenever possible, try to cache your query results. Every time you call $(‘.something’) it is querying the DOM. So if you cache the results in a variable only one query needs to be made. Obviously only do this if you know the DOM hasn’t changed in the interim. In our case here, we know the DOM has changed but we only want to affect the elements that had “sborder” a second ago.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason my code here (this is the entire thing) doesnt actually render
for some reason this code wont work, it doesn't seem to read the javascript.php
For some reason, this code does not actually draw my bitmap file... or show
For some reason, the following bit of code isn't behaving as I would anticipate
This maybe a really simple question but for some reason my code isn't working.
For some reason this code is printing three values for the highest value in
For some reason this code: <td id=ddlHolidayCity colspan=3> <% for (int i = 0;
for some reason this code isn't working in viewDidLoad , but will work in
For some reason this code executes the parental commands immediately, terminating my semaphores and
For some reason this code is working when i click on the #display div,

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.