[JavaScript][jQuery] Checking for the existence of DOM elements
Tadashi Shigeoka · Tue, January 15, 2013
There are many ways to check for the existence of DOM elements in JavaScript, which can be confusing, but the conclusion is that
document.getElementById("id") != null
seems to be the fastest and best for checking.
コード 速度 document.getElementById("id") != null0.019ms $("selector")[0]0.033ms $("selector").get(0)0.040ms $("selector").size()0.041ms $("selector").length0.069ms $("selector").is("*")0.169ms
That’s all from the Gemba.