I'm trying to reuse a function and it isn't working. I put it like so, and it works fine:
$('.square-container').on('click', '.square', function(event) {
$("#testit").removeClass("main_page");
if ( $(this).hasClass('active') ) {
/* actions here */
} else if ( $(this).hasClass('one') ) {
/* actions here */
} else {
alert('error - nothing found');
};
But if I try this, it runs the function but can't detect anything, and gives the message ' error - nothing found'.
function pic_shift(){
$("#testit").removeClass("main_page");
if ( $(this).hasClass('active') ) {
/* actions here */
} else if ( $(this).hasClass('one') ) {
/* actions here */
} else {
alert('error - nothing found');
};
}
$('.square-container').on('click', '.square', function(event) {
pic_shift();
};