반응형
jQuery $(‘body’).on() vs $(‘document’).on()

 

.delegate()

http://api.jquery.com/delegate/

Using body as the delegate

For best performance, attach delegated events at a document location as close as possible to the target elements. Avoid excessive use of document or document.body for delegated events on large documents.

HTML handle the Drag and Drop events:

$('body').on('dragover', filesDragged).on('drop', filesDropped);

Using document as the delegate

The document element is available in the head of the document before loading any other HTML, so it is safe to attach events there without waiting for the document to be ready.
By default, most events bubble up from the original event target to the document element.

It’s all about Speed!?

테스트 URL : http://jsperf.com/jquery-body-delegate-vs-document-delegate

반응형

+ Recent posts