$('.overview li a').click(function(){
$('#large-img').html("<img src=" + $(this)
.attr('href') + "/>" + "<br /><div>" + $(">.desc",this)
.html()); //HOW TO FADEIN this
return false;
});
Asked
Active
Viewed 191 times
2

kapa
- 77,694
- 21
- 158
- 175

user555600
- 164
- 1
- 4
- 11
-
Please post your HTML as well – Michael Robinson Jun 08 '11 at 06:49
-
2possible duplicate of [Why doesn't jquery fadeIn() work with .html()?](http://stackoverflow.com/questions/1490563/why-doesnt-jquery-fadein-work-with-html) – balexandre Jun 08 '11 at 07:14
2 Answers
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;
});
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;
});

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