<div class="hasicon">
<img src="blah.jpg" class="icon" />
</div>
CSS:
.icon { display: none; }
.hasicon { position: relative; }
.hasicon .icon {
display: block;
position: absolute;
top: 0;
right: 0;
width: 32px;
height: 32px;
cursor: pointer;
}
jQuery:
$('body').on('click', '.hasicon > .icon', function() {
// do something
});
To implement this functionality, just include the hasicon
class on the div. Only those with this class will show the icon.
UPDATE:
If necessary, you can also use an empty span instead:
<div class="hasicon">
<span></span>
</div>
CSS:
.hasicon { position: relative; }
.hasicon > span {
display: block;
position: absolute;
top: 0;
right: 0;
width: 32px;
height: 32px;
cursor: pointer;
background: url('myImage.png') center no-repeat;
}
jQuery:
$('body').on('click', '.hasicon > span', function() {
// do something
});