jQuery addClass example

Change class name on click in jQuery

by Kai_Draord

HTML

<div id="section-2">
  <div class="scroll_sec">
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  x<br>
  </div>
</div>

CSS

#section-2 {
  height: 500px;
}

.scroll_sec {
    width: 50%;
    height: 150px;
    margin: 0 auto;
    overflow-y: auto;
}

JavaScript

canLoadNextbatch = true;

loadNextBatch() {
  console.log('scrolldown');

  this.pageIndex = this.pageIndex + 1;
  if (this.canLoadNextbatch) {
    this.global.getData(`/conditions/latest?start=${this.pageIndex}&length=${this.pageSize}`)
      .pipe(take(1)).subscribe(res => {

        const newBatch = res['data'];
        if (newBatch.length === 0) {
          this.canLoadNextbatch = false;
        }

        this.tempThermometer.next(this.tempThermometer.getValue().concat(newBatch));
        console.log(this.tempThermometer);
      });
  }
}