How to change an element’s CSS class and remove all other classes on click

后端 未结 4 2215
隐瞒了意图╮
隐瞒了意图╮ 2021-02-03 10:49

How do I handle a case in AngularJS 2 where on click of an element it needs to change its own style, and if other elements have that style they need to have it removed — prefera

4条回答
  •  眼角桃花
    2021-02-03 11:09

    I have one hard solution to this problem:

    > I'm a div that gets styled on click

    app:

    class App {
    constructor() {
    }
    onclick(event){
        var l = event.target.parentElement.getElementsByClassName("my-class");
        var count = l.length;
        for(var i=0;i

    Plink: https://plnkr.co/edit/RHqL56GrTiV9olYE1Ars?p=preview

提交回复
热议问题