-3

I am doing a custom gallery where when you click a div it changes the src of the div, so I do:

function change2dd1() {
    $("div.videoSel > img").attr("class", "joanamid");
    $("div.videoSel > img").attr('src', $('.videoSel2 > img').attr('src'));
}   

I also try to change the class of the img, so that when I click on it, I get a full screen version, which I use:

$('.Fullscreen').css('height', $(document).outerWidth() + 'px');
//for when you click on an image
$('.joanamid').click(function () {
    var src = $('.joanafull').attr('src'); //get the source attribute of the clicked image
    $('.Fullscreen img').attr('src', src); //assign it to the tag for your fullscreen div
    $('.Fullscreen').fadeIn();

    if(imgChecker.height() > imgChecker.width()) {
        $(".Fullscreen img").css({"display":"block", "margin":"5% auto","z-index":"20","top":"0", "width":"30%",
"height":"40%"});
    }
});

The problem is that the change class is not working at all, it keeps the same class that the div first possesses. Any suggestions?

Termininja
  • 6,620
  • 12
  • 48
  • 49
kanjas
  • 73
  • 1
  • 8
  • 1
    You should use [`addClass()`](https://api.jquery.com/addclass/) and [`removeClass()`](https://api.jquery.com/removeclass/), not try to edit the attributes. – worldofjr Dec 28 '15 at 16:32

1 Answers1

1

Use event delegation:

$("body").on("click", '.joanamid', funciton() {
  // ...
});
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177