You could use jQuery.one() function or jQuery.off()
I think the best solution here could be the use of jQuery.off('click')
$("img").click(function(){
$("img").off('click');
});
and then, re-enable when the alert is triggered
Example: http://jsfiddle.net/c7puz/
JS
// function to do something when the click is trigger
function enableSelect(){
$("img").click(function(){
$(this).toggleClass("hover");
// toggle off the click, so only first one will work,
// until the function is called again
$("img").off('click');
});
}enableSelect();
$("#btn").click(function(){
var pos = $("img.hover").parent().index();
if(pos > -1){
// tell us the selected image to work with
alert('The selected image is at position: ' + pos );
// clear the hover state
$("img").removeClass("hover");
// and enable the click again
enableSelect();
} else {
alert('no image selected');
}
});
Good luck ;-)