Алексей Мирный Алексей Мирный - 2 months ago 13
jQuery Question

jQuery Show image in a div with a third click

function () {
var i = 0;
$('.class').click(i=i+1)
if(i=3) {
$('.class2').css('display','block');
}
}


This code does not work, Please help me.

Answer

Should be :

$(function() { //ready function
    var i = 0;

    $('.class').click(function(){ //Attach click event to '.class'
        i=i+1; //Or i++;

        if(i===3) { //Use triple equal '===' for comparaison
            $('.class2').css('display','block');
        }
    })
})

Hope this helps.