If you inspect the calendar element, you can access the HTML structure generated by the plugin. It is easy to notice that the divs
that have related events have the class .c-event
, along with an attribute data-event-day
that has the day of the event. Therefore, to interact with the days that have events, just do:
$(".c-event").on("click", function (e) {
var day = $(this).attr("data-event-day");
alert(day);
});
This way, if the day 25 has event and we click on it, an alert with the content 25 is displayed. Also by the browser inspector, we can see that the events that appear on the screen have the class .c-event-item
and also have the same attribute data-event-day
. In this way, we can determine, according to the value of this attribute, which elements should be displayed or hidden on the page when clicking in a day. This is done as follows:
$(".c-event").on("click", function (e) {
var day = $(this).attr("data-event-day");
$(".c-event-item[data-event-day!=" + day + "]").hide();
$(".c-event-item[data-event-day=" + day + "]").show();
});
Thus, by clicking on the 25th, only the events of this day will be displayed. If we click on another day, only the events of this day will be displayed.
An example can be seen working here.
All: the code works perfectly for events that are already loaded on the page, but not for events that are outside the initial range. This happens because the event click
is assigned only when the page is loaded, but not when the range of days is changed, generating new elements.
Is the rest of the function not pertinent to your problem? And the HTML code?
– Woss
Ola Anderson, html only calls js
– py3uf
Check the example, and sources http://www.py3uf.qsl.br/test/
– py3uf