Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery .each - get all objects in one element

0 votes
37 views
added Sep 5 in jQuery by LC Marshal Lieutenant (14,830 points)
retagged Oct 5 by LC Marshal
//clone every image to popup element when click 
var floorplanImg = $('.detail-content.floorplan img'),
    imgModal = $('.global-overlay-modal');
$(floorplanImg).addClass('pop-floorplan');

$(floorplanImg).each(function(index) {
    $(this).on('click', function(){
        $(imgModal).fadeIn(300).addClass('active').show();
        var imgSingle = $(this).clone();
        $('.img-popup-detail').html(imgSingle); 
        // console.log($(this).attr('src'));
        if($(imgModal).hasClass('active')) {
            $(imgModal).click(function (){
                $(this).fadeOut(300); 
            });
        }
    });
});

 

1 Response

0 votes
responded Oct 5 by LC Marshal Lieutenant (14,830 points)

To remove class on active element of .each method

$(document).ready(function()
{
    $('.click_me').click(function()
    {       
        $("li.active").not(this).removeClass('active');
        $(this).toggleClass("active");
    });
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...