Reputation: 945
In this code, im comparing if the anchor clicked have a different rel attribute string in comparison to the form's id string.
$('.title a').each(function(i){
$('.title a:eq('+i+')').click(function(e){
e.preventDefault();
$('.title a').removeClass('active');
$(this).addClass('active');
var rel = $(this).attr('rel'),
formId = $('form').attr('id');
if (formId!=rel) {
$('form[id!='+rel+']').fadeOut(200, function(){
$('form[id='+rel+']').fadeIn(200);
});
}
});
});
the first time i click, it works well. But if i click again it wont work and i cant find the problem, can someone help me?
jsfiddle: http://jsfiddle.net/z4MMw/
Upvotes: 0
Views: 63
Reputation: 152206
You can try with:
$('.title a').click(function(e){
e.preventDefault();
$('.title a').removeClass('active');
$(this).addClass('active');
var rel = $(this).attr('rel');
$('form#' + rel).fadeIn(200, function(){
$('form:not(#' + rel + ')').fadeOut(200);
});
});
I've inverted fades, so if there is a form with given ID, it will fadeId, otherwise othing will happen.
Upvotes: 2