jQuery .each - get all objects in one element

0 votes
289 views
added Sep 5, 2018 in jQuery by LC Marshal Captain (25,790 points)
retagged Oct 5, 2018 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, 2018 by LC Marshal Captain (25,790 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.
...