JQuery addclass to selected div, remove class if another div is selected

后端 未结 6 1287
栀梦
栀梦 2020-12-23 14:38

I\'m making a formbuilder, I would like to change the appearance of for example a heading div. When clicked it should get a border but when another dynamically generated div

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 15:30

    In this mode you can find all element which has class active and remove it

    try this

    $(document).ready(function() {
            $(this.attr('id')).click(function () {
               $(document).find('.active').removeClass('active');
               var DivId = $(this).attr('id');
               alert(DivId);
               $(this).addClass('active');
            });
      });
    

提交回复
热议问题