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

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

    **This can be achived easily using two different ways:**
    
    1)We can also do this by using addClass and removeClass of Jquery
    2)Toggle class of jQuery
    
    **1)First Way**
    
    $(documnet.ready(function(){
    $('#dvId').click(function(){
      $('#dvId').removeClass('active class or your class name which you want to    remove').addClass('active class or your class name which you want to add');     
    });
    });
    
    **2) Second Way**
    
    i) Here we need to add the class which we want to show while page get loads.
    ii)after clicking on div we we will toggle class i.e. the class is added while loading page gets removed and class which we provide in toggleClss gets added :)
    
    

提交回复
热议问题