-2

リストをクリックすると、タグ内に div が追加されるスクリプトを作成しようとしています<li>。これは問題ありませんが、別の問題をクリックすると、<li>挿入する前に div を削除したいのですがそれをして、クラス .selected も削除したいですか? ありがとう。

$(document).on('click', '#horiz_container img', function() {
            var img_selected = $(this);
            var value_sport = img_selected.val();
            if (!$(this).closest('li').is('.selected')) {

                $(this).closest('li').addClass('selected');
                $(this).closest('li').prepend('<div class="selected_sport"><img src="' + CI_ROOT +'resources/img/select.png"></div>');
            }

        });
4

2 に答える 2