0

For the sake of clarity and to be succinct I've created this script which has to functions, to run the checkSize method on page-load and run the script when the browser resizes. My problem is that I cannot get execute the checkSize at all.

Any help would be greatly appreciated!!

class thisDiv {
    constructor() {
        this.element = $('.div');
        this.window = $(window);
        this.checkSize();
        this.events();
    }
    events() {
        this.window.resize(this.checkSize);
    }
    checkSize() {
        this.element.addClass('red');
    }
}
export default thisDiv;
Timber Hjellum
  • 330
  • 2
  • 7
  • You aren't listening (therefore not responding) to any events. investigate `.addEventListener()`: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener – Randy Casburn May 11 '18 at 23:17
  • 1
    @RandyCasburn: `this.window` is a jQuery object, so `this.window.resize(this.checkSize)` attaches an event listener. – Ry- May 11 '18 at 23:19
  • `this.window.resize(this.checkSize.bind(this))`, explanation in the duplicates. – Ry- May 11 '18 at 23:20

0 Answers0