jQuery addClass example

Change class name on click in jQuery

HTML

<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css">
<script src="https://bossanova.uk/jtools/v2/japp.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jtools/v2/japp.css">
<div id="titleDiv"></div>
<div id="worksheet" class="worksheet"></div>

CSS

.worksheet {
  width: 100%;
}

.required {
  border: 1px dashed #f00 !important;
}
.dummy{}

JavaScript

var data = [];
var table = jexcel($('#worksheet').get(0), {
  columns: [{
      "title": "Origin",
      "width": 155,
      "align": "left",
      "type": "text"
    },
    {
      "title": "Destination",
      "width": 191,
      "align": "left",
      "type": "text"
    },
    {
      "title": "Directionality",
      "width": 161,
      "align": "left",
      "type": "text"
    },
    {
      "title": "Discount Percent",
      "width": 146,
      "align": "left",
      "type": "text"
    }  ],
  columnDrag: false,
  columnSorting: false,
  columnResize: true,
  rowDrag: false,
  allowInsertColumn: false,
  allowManualInsertColumn: false,
  allowDeleteColumn: false,
  allowRenameColumn: false,
  allowComments: false,
  search: false,
  onselection: worksheet_OnChange
});

// this line adds the key to the element causing the Object.keys
// check in setValue function to think the cell is a jQuery object.
$('#worksheet table td').data('dummyData', 1);

$('#titleDiv').text('Title DIV text is set');

function worksheet_OnChange(instance, x1, y1, x2, y2) {
  $(instance).find('table td.required').removeClass('required');

  var data = table.getData(false);
  console.log(JSON.stringify(data));
  for (var row = 0; row < data.length; row++) {
    for (var col = 0; col < data[row].length; col++) {
      var cellValue = data[row][col];
      console.log(cellValue);
      if (cellValue === undefined || cellValue == null || cellValue == '') {
        $(table.records[row][col]).addClass('required');
      }
    }
  }
}