<input type="text" name="name" value="" id="name"/>
<input type="text" name="subject" value="" id="subject" />
<input type="text" name="message" value="" id="message" />
Can someone tell me the difference if I selected individually the inputs or getting them in one swap.
like
var name = jQuery('#name');
var subject= jQuery('#subject');
var message = jQuery('#message');
as compared to getting them in one swap
jQuery(":input").each(function(){....};)
i mean wouldn’t jquery have to go back to the document root everytime I call <input type="text" name="name" value="" id="name"/> ?
and if from my example I do this
<input type="text" name="message" value="" id="message" />
<input type="text" name="name" value="" id="name"/>
which means i queried the last input form then queried back the first input form, wouldnt it make the flow slower?
jQuery('#name');will be faster thenjQuery(":input"), by a lot.jQuery('#name')will match the selector as an ID and return the item by ID, while:inputwill traverse the entire dom for elements that are of type input.If you’re really worried about selector performance, take a look at http://www.paulirish.com/perf