I have been trying to remove this #static id from the one click function below and make a use of variable so that it automatically gets the Ids' like #static, #dynamic...etc and puts it in One click function. This will save me copying and pasting the same function again and again just by changing it's ID names. Plus this will also make the code look clean & short.
jQuery(document).ready(function($){
// Home Page Static Portfolio Ajax Query
$(this).one('click', '#static', function( e ){
var that = $(this);
var id = that.attr('id');
var rel = that.data('rel');
var ajaxurl = that.data('url');
$.ajax({
url : ajaxurl,
type : 'POST',
data : {
rel : rel,
action : 'home_filter_' + id + '_portfolios'
},
error : function( response ){
console.log( response );
},
success : function ( response ){
if ( response == '' ) {
$('figure' + id).after( '<div class="end_of_testimonial"><h3>You have reached the end of the line</h3><p>No more portfolios to load!</p></div>' );
} else {
$('.gallery-wrapper').append( response );
}
}
});
});
Any help would be greatly appreciated :)