开发者

select and deselect images on a web page with jquery

开发者 https://www.devze.com 2023-01-29 06:46 出处:网络
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 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.

select and deselect images on a web page with jquery


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();
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消