I'm facing an issue with my jQuery code where two divs contain lists of links, triggering AJAX calls to append JSON data to a separate div. Upon clicking a link, the corresponding link div should hide. There's also a third div with the class "panel-close" that resets the view by removing the appended data and showing the link div again.
The problem arises when sometimes the link div does not reappear after removing the data container, or the JSON data fails to append on subsequent clicks. Here is the basic structure of my HTML:
<div class="curation-panel">
<div class="curation-contents-list">
<a class="load-article"></a>
</div>
<div class="article-container"></div>
</div>
<div class="film-panel">
<div class="film-contents-list">
<a class="load-project"></a>
</div>
<div class="project-container"></div>
</div>
<div class="panel-close"></div>
Below is the jQuery code I've implemented:
$(function(){
var element = $('.load-article');
var url = element.data('page') + '.json';
var target = $('.article-container');
$(element).on('click', function(e) {
e.preventDefault();
$.get(url, function(data) {
$('.curation-contents-list').hide();
$(target).append(data);
});
$("body").addClass("load-article-is-open"),
$(this).animate({
scrollTop: 0
}, 300, "easeInOutExpo")
});
}),
$(function(){
var element = $('.load-project');
var url = element.data('page') + '.json';
var target = $('.project-container');
$('.load-project').on('click', function(e) {
e.preventDefault();
$.get(url, function(data) {
$('.film-contents-list').hide();
$(target).append(data);
});
$("body").addClass("load-project-is-open"),
$(this).animate({
scrollTop: 0
}, 300, "easeInOutExpo")
});
}),
$(".panel-close").click(function() {
$("body").removeClass("curation-panel-is-open").removeClass("film-panel-is-open").removeClass("load-article-is-open").removeClass("load-project-is-open"),
$(".curation-panel").animate({
scrollTop: 0
}, 300, "easeInOutExpo"),
$(".film-panel").animate({
scrollTop: 0
}, 300, "easeInOutExpo"),
$('.curation-contents').show();
$('.film-contents-list').show();
$('.article-container').remove();
$('.project-container').remove();
});