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

后端 未结 6 1292
栀梦
栀梦 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:16

    You can use a single line to add and remove class on a div. Please remove a class first to add a new class.

    $('div').on('click',function(){
      $('div').removeClass('active').addClass('active');     
    });
    

提交回复
热议问题