I have list of images on the web page. I wa开发者_如何学编程nt to click on image to select it and want to display selected image on the same page. By clicking on selected image, i want to deselect it. I have displayed the sketch below. Can someone please help me with jquery code, how to do it. Thanks a lot.
Here is something to start with.
$('#selectList img')
.each(function(i, el){
$(this).addClass('img' + i); // identtify imgs by index (class="imgN")
})
.click(function(){
var $img = $(this).toggleClass('clicked');
if($img.hasClass('clicked'))
output.append($img.clone().removeClass('clicked'));
else
output.find('.' + $img[0].className).remove();
});
精彩评论