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

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

    I had to transform the divs to list items otherwise all my divs would get that class and only the generated ones should get it Thanks everyone, I love this site and the helpful people on it !!!! You can follow the newbie school project at http://low-budgetwebservice.be/project/webbuilder.html suggestions are always welcome :). So this worked for me:

                /* Add Class Heading*/
                $(document).ready(function() {
                $( document ).on( 'click', 'ul#items li', function () { 
                $('ul#items li').removeClass('active'); 
                $(this).addClass('active');
                });
                });
    

提交回复
热议问题