jQuery addClass example

Change class name on click in jQuery

by Dhanck

HTML

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.6/css/all.css">
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<link rel="stylesheet" href="https://cdn.quilljs.com/1.3.6/quill.snow.css">
<div class="header">
  <span class="toggle-btn">
    <span>Expand All</span>
    <span>Collapse All</span>
  </span>
  <span class="create-btn">
    <i class="fas fa-plus"></i>
    Create Note Group
  </span>
</div>
<table>
  <colgroup>
    <col width="30%">
    <col width="150px">
    <col>
    <col>
    <col>
    <col width="100px">
  </colgroup>
  <thead>
    <tr>
      <th>Name</th>
      <th>Date Modified</th>
      <th colspan="2">Documents</th>
      <th colspan="2">Actions</th>
    </tr>
  </thead>
  <tbody>
    <tr class="note">
      <td>New Note 1</td>
      <td>09 Sep '19 04:32 PM</td>
      <td colspan="2">data</td>
      <td colspan="2">
        <i class="fas fa-plus"></i>
        <i class="fas fa-edit"></i>
        <i class="fas fa-trash-alt"></i>
      </td>
    </tr>
    <tr class="sub-note">
      <th>Name</th>
      <th>Date Modified</th>
      <th>Accounts</th>
      <th>Laguage</th>
      <th>Dates</th>
      <th>Actions</th>
    </tr>
    <tr class="sub-note">
      <td>New Note 1</td>
      <td>09 Sep '19 04:32 PM</td>
      <td>
        <span class="sub-note-expand">
        <i class="fas fa-plus"></i>
          Invesco Canadian Pemier Growth Fund, </br>
Invesco Global Consumer Trends Fund, </br>
Invesco Select Canadian Equity Fund, </br>
Invesco S&P 500 Low Volatility High Dividend Index, </br>
Invesco Canadian Fund, </br>
Invesco Canadian Endeavour Fund, </br>
Invesco Canadian Opportunity Class, </br>
Invesco Canadian Plus Dividend Class, </br>
Invesco Canadian Small Companies Fund, </br>
Invesco Emarging Markets Class - Canada, </br>
Invesco Energy Class - Canada, </br>
Invesco Global Companies Fund - Canada, </br>
Invesco Global Dividend Class - Canada, </br>
Invesco Global Endeavour Fund - Canada, </br>
Invesco...

CSS

*{
  margin: 0;
}
body {
  background-color: #f7f7f7;
  font-family: 'Arial';
  font-size: 12px;
}
i{
  padding: 0 5px;
  cursor: pointer;
}
i:hover{
  color: #03A9F4;
}

.header{
      background-color: #fafafa;
    display: flex;
    height: 36px;
    overflow: hidden;
    padding: 7px;
    justify-content: space-between;
}
.header i{
  color: #99cc33;
  font-size: 20px;
}
.create-btn {
    height: 40px;
    display: flex;
    align-items: center;
    cursor: pointer;
}
.toggle-btn{
  height: 40px;
    display: flex;
    align-items: center;
}
.toggle-btn span {
    background: #e1e1e1;
    border: 1px solid #c8c8c8;
    padding: 2px 5px;
    cursor: pointer;
}
table {
  border-collapse: collapse;
  border-spacing: 0px;
  width: 100%;
  color: #4b4b4b;
}

table th {
  background: #D7D7D7;
}

table .sub-note th {
  background: #DADADA;
}

.sub-note td:first-child {
  padding-left: 25px;
}

table td:last-child{
  text-align: right;

}
table td:last-child i{
  display: none;
}
table tr:hover > td:last-child i{
  display: inline-block;
}

table,
th,
td {
  padding: 5px;
  border: 1px solid #ccc;
}
.sub-note th{
  padding: 3px;
}
/* table tr:hover{
  background: #fdfade;
  cursor: pointer;
} */
.note:hover {
  background: #fdfade;
  color: #4b4b4b;
}

.sub-note:hover,
.sub-note:nth-child(even):hover {
  background: #fdfade;
}

.note {
    background: #2F6CA8;
    color: #fff;
}

.sub-note {
  background: #EFF8FB;
}

.sub-note:nth-child(even) {
  background: #B1DBEA;
}
.sub-note-expand {
    height: 16px;
    overflow: hidden;
    display: block;
}




/* Popup frame style */
* {
  margin: 0px;
  padding: 0px;
  font-family: Arial;
  font-size: 13px;
}

/* .frame {
  margin: 10px;
  max-width: 1014px;
  background: #fafafa;
  height: 600px;
  box-shadow: 3px 6px 12px rgba(0, 0, 0, 0.4);
} */
.frame {
    position: absolute;
    right: 0;
    left: 0;
    margin-left: auto;
    margin-right: auto;
    top: 0;
    bottom: 0;
    margin-top: auto;
    margin-bottom:...

JavaScript

$('.frame, .bg-ful-cover').hide();
$('.sub-note').hide();
/* $('.note').click(function() {
  $(this).closest('tr').nextUntil('.note').toggle(); 
}); */

$('.fa-edit').on(
'click', function(){
  $('.frame, .bg-ful-cover').toggle();
})
$('.sub-note td').on(
'dblclick', function(e){
  e.preventDefault();
  $('.frame, .bg-ful-cover').toggle();
});
$('.bg-ful-cover').on(
'click', function(){
  $('.frame, .bg-ful-cover').toggle();
})


    $('.sub-note-expand').on('click', '.fa-plus', function(){
      $('.sub-note-expand').height('auto');
      $('.sub-note-expand i').addClass('fa-minus');
      $('.sub-note-expand i').removeClass('fa-plus');
    })
    $('.sub-note-expand').on('click', '.fa-minus', function(){
      $('.sub-note-expand').height( 16 );
      $('.sub-note-expand i').addClass('fa-plus');
      $('.sub-note-expand i').removeClass('fa-minus');
    })



var DELAY = 300, clicks = 0, timer = null;
$(function(){
    $(".note").on("click", function(e){
        clicks++;
        $note = $(this);
        if(clicks === 1) {
            timer = setTimeout(function() {
                $note.closest('tr').nextUntil('.note').toggle();
                clicks = 0;
            }, DELAY);
        } else {
            clearTimeout(timer);
            $('.frame, .bg-ful-cover').toggle();
            clicks = 0;
        }
    })
    .on("dblclick", function(e){
        e.preventDefault();  //cancel system double-click event
    });
});





  //Setting quill with custom dropdown
  var quill = new Quill('#editor', {
    theme: 'snow',
    modules: {
      toolbar: {
        container: [
          [{
            'font': []
          }],
          [{
            'size': ['small', false, 'large', 'huge']
          }],
          ['bold', 'italic', 'underline', 'strike'],
          [{
            'color': []
          }, {
            'background': []
          }],
          [{
            'list': 'ordered'
          }, {
            'list': 'bullet'
          }],
          [{
 ...