I made a function using jQuery and Ajax to append info from a separate PHP file to another file. Lets call the destination file "Homepage" and the file containing the data "Template".
So i use this function:
var box = $('#infoPageContainer'),
close = $('.arrow');
btn1.click( function(){
event.preventDefault();
if( box.hasClass( 'active' )){
box.removeClass( 'active' );
box.css( "width", "0%" );
$('#placeholder1').fadeOut(600);
setTimeout(function(){
$('#placeholder1').html("");
},1000);
} else {
box.addClass('active');
box.css( "width", "100%" );
$.ajax({
url: 'template/parts/Template.php',
success: function(data){
$('#placeholder1').html(data).fadeIn(600);
},
beforeSend: function(){
$('#placeholder1').html("loading").fadeIn(600);
}
});
}
});
To append this data:
<div class="mainImgContainer1 templateImgContainer"></div>
<div class="textContainer">
<img src="img/arrow-01.png" alt="arrow" class="arrow">
<div class="titleContainer"><h3>Veldopstellingen</h3></div>
<div class="textWrapper">
<h4>Dit is de titel</h4>
<p class="broodTekst">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
</div>
</div>
As you can see I use a switch that checks for an 'Active' class and runs the respective function. What I want however, is the function removing the appended data to be triggered by a button that is appended (Img with Arrow class). So like this:
close.click( function(){
event.preventDefault();
box.removeClass( 'active' );
box.css( "width", "0%" );
$('#placeholder1').fadeOut(600);
setTimeout(function(){
$('#placeholder1').html("");
},1000);
});
But when I do so, nothing happens even tho the function does work when I don't use an appended object as trigger. What should I do?