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 :(.
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:
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:
On a best practices note, when using jQuery…