2
$('.overview li a').click(function(){
        $('#large-img').html("<img src=" + $(this)
                           .attr('href') + "/>" + "<br /><div>" + $(">.desc",this)
                           .html()); //HOW TO FADEIN this
        return false;
        });
kapa
  • 77,694
  • 21
  • 158
  • 175
user555600
  • 164
  • 1
  • 4
  • 11

2 Answers2

4

.fadeIn() can only be called on jQuery collections. html() returns a string, so it cannot be used on that. One possible route is to create a jQuery collection out of your HTML (that you want to insert), hide it, then append it to its place and fade it in.

This code does this:

$('.overview li a').click(function(){
    var $newstuff=
        $("<img src=" 
        + $(this).attr('href') 
        + ">"
        + "<br><div>" 
        + $(">.desc", this).html()
        + '</div>').hide();

    $('#large-img').append($newstuff.fadeIn('slow'));
    return false;
});

jsFiddle Demo

And the same code in a bit more jQuery-ish way:

$('.overview li a').click(function(){  
    $('<img>').attr('src', $(this).attr('href'))
        .add('<br>')
        .add($('<div>').html($(">.desc", this).html()))
        .hide()
        .appendTo($('#large-img'))
        .fadeIn('slow'); 
    return false;
});

jsFiddle Demo 2

kapa
  • 77,694
  • 21
  • 158
  • 175
  • hi i have a problem with the image path it adds a slash at the end "img.jpg/" the server cant read it when i upload – user555600 Jun 08 '11 at 09:08
  • @user555600 I would gladly help, but as a developer yourself, you understand that it would quite hard without knowing your HTML, your exact URL you have problem with and possibly your browser. Best way would be to create a test case or jsFiddle and ask another question. – kapa Jun 08 '11 at 09:11
0

Give this a try:

$('.overview li a').click(function(){
    var a = this;
    var img = $("<img src='" + $(this).attr('href') + "'/>" +  "<br /><div>");
    $('#large-img').hide('fast', function(){ 
        $(this).html(img + $(">.desc", a)).show('fast'); 
    });
    return false;
});
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
  • hi i have a problem with the image path it adds a slash at the end "img.jpg/" the server cant read it when i upload – user555600 Jun 08 '11 at 09:09