(function($) { $(document).ready(function(){ $(document).on('click','a.feature',function(){ postId = $(this).closest('tr').attr('id').replace('post-',''); if($(this).find('span.fa-star').length){ //make unfeature list data = {action:'add_feature_list',feature : 'false',id : postId} $(this).find('span').removeClass('fa-star').addClass('fa-star-o'); }else{ //make feature list data = {action:'add_feature_list',feature : 'true',id : postId} $(this).find('span').removeClass('fa-star-o').addClass('fa-star'); } $.fn.ajax_action(data) }) $.fn.ajax_action = function(postData){ $('.wrap #message').remove() $.ajax({ url: ajaxurl, type: 'POST', dataType: 'json', data: { action: 'adlisting_ajax', adlAjaxData: postData, security: WP_ADL.security }, beforeComplete: function(){ $('.wrap h1').after('
Loading...
') }, success: function(response){ $('.wrap #message').remove() if(response.success === true){ console.log(response.data); $('.wrap h1').after('

'+response.data+'

') }else{ console.log(response.data); $('.wrap h1').after('

'+response.data+'

') } }, error: function(error){ console.log(error); $('.wrap h1').after('

'+error.data+'

') } }) } }) })(jQuery);