Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery $(this) not working inside a function parameter

The following code doesn't work:

$(".countdown").circularCountdown({

    startDate:$(this).attr('data-start'),
    endDate:$(this).attr('data-end'),
    timeZone:$(this).attr("timezone")

});

The one below works fine,

$(".countdown").circularCountdown({

    startDate:$(".countdown").attr('data-start'),
    endDate:$(".countdown").attr('data-end'),
    timeZone:$(".countdown").attr("timezone")

});

I don't get it, doesn't the $(this) reference ".countdown" since I'm calling the function on this element? Could someone please help me out?

like image 223
sigmaxf Avatar asked Aug 01 '14 11:08

sigmaxf


1 Answers

Because this does not refer to the countdown so one solution is to use each()

$(".countdown").each(function () {
    $(this).circularCountdown({
        startDate: $(this).attr('data-start'),
        endDate: $(this).attr('data-end'),
        timeZone: $(this).attr("timezone")
    });
})
like image 115
Arun P Johny Avatar answered Oct 14 '22 01:10

Arun P Johny