know when the button is pressed day, week or month in full calendar


Good I need for javascript or jquery know if you have clicked or clicked on the day button week or month of fullcalendar.

already the fullcalendar works is created dynamically from javascript adds events etc. in the there are at this moment three buttons see in the next fragment;

header: {
         left: 'agendaDay,agendaWeek,month',
         center: 'title',
         right: ''

if I need to click on either the agendaDay, agendaWeek or month to know that click is given because full calendar adds classes and not id and I do not know how to take these values. for example with the following buttons and behind you can do this:

in the html:

<button id='next'><span  class='fc-text-arrow'><strong >›</strong></span></button>

in javascript:

$('#prev').on('click', function() {

But with the week and month day buttons it does not work, nothing comes out in the documentation "according to what I've read" and for javascript try this:


to try to assign id to the button of the day this is added but not within the element in specific so when pulse click does not call any event eye probe with an alert ("etc")

asked by Erwis Álvarez 26.11.2018 в 18:44

2 answers


According to the library of FullCalendar , that is the correct way to get the day, month and year depending on the day that you des click :

$(document).ready(function() {
     dayClick: function(date, jsEvent, view) {
        console.log(date.month()); //day of the week: 1 for monday
        console.log(date.get('date')); //day of month: 20 for today
<script src=""></script>
<link href="" rel="stylesheet"/>
<script src=""></script>
<script src=""></script>
<div id='calendar'></div>

It has its function called dayClick which is the one that takes care of everything.

I hope it serves you. Greetings.

answered by 26.11.2018 в 20:27

To know which button has been pressed you can use the generic CSS class that the buttons of the bar use and filter by the content of your text. This example will print on the console the text of the button pressed ('week', 'day', 'list', 'month') with which you can filter


And an alternative and valid option is to add an event for each button:

        //hacer lo que debes hacer
        //hacer lo que debes hacer
        //hacer lo que debes hacer

In either case you must place this code once the component is initialized or use the event eventAfterAllRender

answered by 26.11.2018 в 20:07