0

Using jQuery 3.6.1. My code is:

OSH.setDivisions = function() {
let rows = $("input[name^='compdiv']");
rows.on("blur", OSH.doDivisions(rows))
}

OSH.doDivisions = function(rows) {
    alert("in doDivisions()");
    if (OSH.emptyDivisions(rows) == 0) {
        OSH.addDivision();
    }
}

Stepping through this in Chrome developer tools, the rows.on() line causes the alert() to pop up without doing anything to the page. And if I dismiss the alert and cycle through the various "compdiv" input fields, either with the TAB key or using the mouse, the alert never triggers again. This makes no sense to me.

What am I doing wrong?

sootsnoot
  • 2,178
  • 3
  • 22
  • 27
  • 1
    Because when you put `(arguments)` after a function name, it calls the function. Just like `console.log(someFunction())` will call the function and log what it returns. – Barmar May 27 '23 at 15:29
  • 1
    Use an anonymous function to call it later: `() => OSH.doDivisions(rows)` – Barmar May 27 '23 at 15:30

0 Answers0