以下のワンクリック機能からこの#static
idを削除して自動的に取得しようとしています「#static
」、「#dynamic
...」などのIdsをワンクリック機能に入れています。これにより、ID名を変更するだけで、同じ機能を何度も何度もコピーして貼り付ける手間を省くことができます。さらに、これはコードがきれいに見えるようにします&短いです。クリックした要素のIDを取得し、変数に格納してAJAX呼び出しを行う関数で使用する方法
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);
}
}
});
});
任意の助けいただければ幸いです:)あなたのコード行で
それは '.on()'の代わりに '.one()' ...あなたの質問を編集してくださいを使用する方法についてだけではない場合。あなたの問題はよりよく定義できます。 *あなたは何を期待していますか? –