As far as JavaScript goes, I’d suggest using jQuery to add a class to all links that contain an image:
$('#sidebar a:has(img)').addClass('image-link');
(The :has
selector is a jQuery thing; it isn’t present in CSS.)
Then adjust your stylesheet accordingly.
#sidebar a:hover {
border-bottom: 1px dotted red;
}
#sidebar a.image-link:hover {
border-bottom: none;
}