HTML / Javascript - Expand and collapse table rows (childs) by clicking on a parent row

后端 未结 1 1435
悲&欢浪女
悲&欢浪女 2021-02-04 13:13

I am trying to solve one issue since days and finally understood that I will not succeed without help ... I want to do a common thing that we see on internet everyday : be able

1条回答
  •  旧巷少年郎
    2021-02-04 13:53

    You will need to wrap each group of parent + children in a for this and use a small script to toggle a class name on this parent . Here's an example:

    $('table').on('click', 'tr.parent .fa-chevron-down', function(){
      $(this).closest('tbody').toggleClass('open');
    });
    .parent ~ .cchild {
      display: none;
    }
    .open .parent ~ .cchild {
      display: table-row;
    }
    .parent {
      cursor: pointer;
    }
    tbody {
      color: #212121;
    }
    .open {
      background-color: #e6e6e6;
    }
    
    .open .cchild {
      background-color: #999;
      color: white;
    }
    .parent > *:last-child {
      width: 30px;
    }
    .parent i {
      transform: rotate(0deg);
      transition: transform .3s cubic-bezier(.4,0,.2,1);
      margin: -.5rem;
      padding: .5rem;
     
    }
    .open .parent i {
      transform: rotate(180deg)
    }
    
    
    
    
    
    
    
    
    
    
    
    
    Age Sex Name From
    100 M Dodo UK
    10 M Child UK
    10 M Child UK
    10 M Child UK
    100 M Dodo UK
    10 M Child UK
    10 M Child UK
    10 M Child UK

    0 讨论(0)
提交回复
热议问题