Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onClick event #19

Open
AhmadiRamin opened this issue Jul 8, 2017 · 1 comment
Open

onClick event #19

AhmadiRamin opened this issue Jul 8, 2017 · 1 comment

Comments

@AhmadiRamin
Copy link

Hi,
how can I raise onClick event , when a user click on a date ?

@faustyn-p
Copy link

I think it is not the best (and most proper) way to do it, but you can do it like this:

  1. Define months array before initialize eCalendar:
    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    You can use this array later, as option of eCalendar:
    $('#calendar').eCalendar({ months: months });

  2. After initialize eCalendar add jquery body onClick event.

$('body').on('click','#calendar .c-day',function(){
    //get day from object you clicked
    var day = $(this).html(); 
    //get month and year from element, and split it to two values
    var month_and_year = $('#calendar .c-month').html().split(' '); 
    //get proper index of array months, and add one, because array starts from 0
    var month = months.indexOf(month_and_year[0]) + 1;  
    //get year
    var year = month_and_year[1];
    //show results in console
    console.log(day + '/' + month + '/' + year); 
});

As you see, I use "body on click", because other way, script won't work after month changes.

I scraped data, because elements does not supply any data by itself.

I hope it will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants