2

I have multiple thumbnails and want the main image to represent a large version of the thumbnail when each thumbnail is rolled over. I appreciate this must be a common usage, but I am struggling to find a simple solution. I have used the following code, which I appreciate may be poor, but this is all quite new for me.. thanks

$('.thumbnail').mouseover(function() {
    var currentimg = $('this').attr('src');
    $('#imageMain img').attr('src', currentimg);
});

I haven't included the HTML as I guess it's pretty clear what I am trying to achieve.

James Johnson
  • 45,496
  • 8
  • 73
  • 110
Pete Norris
  • 1,056
  • 7
  • 24
  • 36

3 Answers3

3

have you tried changing

$('this').attr('src'); 

with

$(this).attr('src');

?

bjornruysen
  • 850
  • 1
  • 6
  • 15
0

You should create a class for both rollover states, and then you can just use the toggleClass function:

$(".thumbnail").hover(function(){
    $(this).toggleClass("rollover");
});
James Johnson
  • 45,496
  • 8
  • 73
  • 110
0

Change $('this') to $(this)

it should work, when using "this" to refer to the current object, it does not need quotes

Huangism
  • 16,278
  • 7
  • 48
  • 74