0
var len1 = $("div").length
// can a new div inserted here?
var len2 = $("div").length
console.log(len1 === len2) // always true?

Is it possible for some rogue script to insert a new div between jQuery calls?

Denis Gorbachev
  • 507
  • 4
  • 12

1 Answers1

2

Short answer: No.

Longer answer: You don't seem to be using alert or confirm in your code, and so the couple of weird edge cases in Firefox (which may only be in older versions) related to alert and confirm don't come into play. This answer from 2010 goes into those in detail.

But no, barring the above, no JavaScript code that accesses the DOM can be run between one statement and another in your code. Browsers run JavaScript with a single UI thread (and zero or more web worker threads, but web worker threads can't access the DOM).

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875