api design - Why does the jQuery library expose DOM elements? -


this question design of jquery api, not specifics of usage.

why jquery object collection of dom elements , not collection of jquery objects?

working jquery objects allow dom manipulation done same way throughout code. seems usage patterns convert dom element jquery object anyway. understand it, many dom-element-to-jquery-object conversions expected, that's why chose shorthand $ function.

why way? why not assume want manipulate dom through jquery , avoid explicit conversions everywhere?

it inefficient create jquery object when 1 isn't needed. example:

$("a").each(function(){     console.log(this.href); }); 

since href available property of domelement, waste turn jquery object , use .attr.

for jquery make each 1 jquery object, have make new jquery object each element iterates over, waste if don't need jquery object. same thought process can applied event handlers, filter method, , other method iterates on elements.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -