Assume that each link holds the href of the image to be shown and is identifiable by class, say link-image
. Further, let's say the display area is set up with a fixed id, imageDisplay
.
$('a.link-image').hover(
function() {
$('#imageDisplay').children().remove();
$('<img src="' + $(this).attr('href') + '" alt="" />')
.css( { height: 100, width: 100 } )
.appendTo( '#imageDisplay' );
},
function() {
$('#imageDisplay').children().remove();
$('<span>No image available</span>').appendTo( '#imageDisplay' );
}
);
You might actually want to use the hoverIntent plugin to prevent flashing as the mouse moves over the links.
Normally, you'd couple this with a click handler on the links that disables the default link behavior.
$('a.link-image').click( function() { return false; } );
Note that you could simply chain the click handler onto the hover handler.