views:

183

answers:

4

i have the following code that is not working properly, what the hell am i doing wrong???

$('#gallerynav ul li a').click(function(){        
var href = $('#gallerynav ul li a').attr('href') 
$("#galleries").children().fadeOut(500 , function(){
(href).fadeIn(500)             
})
})

i have the href of the links set like this

<div id="gallerynav">
<ul>
<li><a href="#foo">link</a></li>
</ul> 
</div>
A: 

It looks like you're missing a $ in front of the (href) call. Try:

$(href).fadeIn(500)
wows
var href will contain the string "#foo" this will be treated like a selector and won't match anything. (nothing in the example anyway) if there is some more markup with the ID="foo" then this looks right.
Myster
A: 

I think: var href = $('#gallerynav ul li a').attr('href');

should be: var href = this.attr('href');

abysslogic
+1  A: 

Try this:

$('#gallerynav ul li a').click(function(evt) {
    var href = this.href;
    $("#galleries").children().fadeOut(500 , function() {
        $(href).fadeIn(500);
    });
    evt.preventDefault();
});
Darin Dimitrov
+3  A: 

Try this.

$('#gallerynav ul li a').click(function(){        
    var link = $(this).attr('href'); 
    $("#galleries").children().fadeOut(500 , function(){
        $(link).fadeIn(500);
    });
});
Kristinn Örn Sigurðsson
this looks right, corrects the problem where the variable is not created with the correct object.
Myster