Is it faster to first check if an element exists, and then bind event handlers, like this:
if( $('.selector').length ) {
$('.selector').on('click',function() {
// Do stuff on click
}
}
or is it better to simply do:
$('.selector').on('click',function() {
// Do stuff on click
}
All this happens on document ready, so the less delay the better.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…