I'm using a template that I found on the internet, when I click on a menu option I update the main content by Ajax
but when I want to get a div
or open a datepicker
, or any other functionality of jquery
, it is no longer possible to do any of this in all the html
that you load by Ajax
.
This is the page that is loaded by default, here you can see that the datepicker
works and the collapse
of the divs
below, but when I charge another HTML
by Ajax
and I show it already I can not use any of these options.
What I did to solve the collapse
of the divs
, was to look for the code of javascript
that activates that and copy it in a new file in this way:
$(function(){
$(document).ready(function() {
$('.collapse-link').on('click', function() {
var $BOX_PANEL = $(this).closest('.x_panel'),
$ICON = $(this).find('i'),
$BOX_CONTENT = $BOX_PANEL.find('.x_content');
// fix for some div with hardcoded fix class
if ($BOX_PANEL.attr('style')) {
$BOX_CONTENT.slideToggle(200, function(){
$BOX_PANEL.removeAttr('style');
});
} else {
$BOX_CONTENT.slideToggle(200);
$BOX_PANEL.css('height', 'auto');
}
$ICON.toggleClass('fa-chevron-up fa-chevron-down');
});
$('.close-link').click(function () {
var $BOX_PANEL = $(this).closest('.x_panel');
$BOX_PANEL.remove();
});
});
});
That solved that problem, but to be able to make all the functionalities of the template operational, I will have to search the entire template for the code parts of each functionality and add it to my file javascript
that I charge with each new page that I open by means of Ajax
.
They know some way of being able to solve this without having to load all the javascript
each time I load a new page by Ajax
.