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">
<div id="mySidebar" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <span class="">New Note 1</span>
  <span class="">New Note 1</span>
  <span class="">New Note 1</span>
  <span class="">New Note 1</span>
</div>


<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>


<div id="main">
<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>data</td>
      <td>data</td>
      <td>data</td>
      <td>
        <i class="fas fa-edit"></i>
        <i class="fas fa-trash-alt"></i>
      </td>
    </tr>
    <tr class="sub-note">
      <td>New Note 1</td>
      <td>09 Sep '19 04:32 PM</td>
      <td>data</td>
      <td>data</td>
      <td>data</td>
      <td>
        <i class="fas fa-edit"></i>
        <i class="fas fa-trash-alt"></i>
      </td>
    </tr>
    <tr class="sub-note">
      <td>New Note 1</td>
    ...

CSS

body {
  font-family: "Lato", sans-serif;
}

.sidenav {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  right: 0;
  background-color: #e4e4e4;
  overflow-x: hidden;
  transition: 0.5s;
  padding-top: 60px;
}

.sidenav a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 25px;
  color: #818181;
  display: block;
  transition: 0.3s;
}

.sidenav a:hover {
  color: #f1f1f1;
}

.sidenav .closebtn {
  position: absolute;
  top: 0;
  right: 25px;
  font-size: 36px;
  margin-left: 50px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}




*{
  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;
  transition: 0.5s;
}

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:...

JavaScript

function openNav() {
$('#main').css( { marginRight : "350px" } );
$('#mySidebar').width('350px');

  //document.getElementById("mySidenav").style.width = "250px";
  //document.getElementById("main").style.marginRigth = "250px";
}

function closeNav() {
$('#mySidebar').width('0');
$('#main').css( { marginRight : '0' } );
  //document.getElementById("mySidenav").style.width = "0";
  //document.getElementById("main").style.marginRigth= "0";
}