Just a quick post to help you guys out there trying to work out how to create a jQuery DOM Element object from a returned jQuery Object
that you got from a code snippet like the one below:
(function ($) {
var elms = $('#a-form').find ('input');
})(jQuery);
Now I’m sure that there are a million better ways to do this in jQuery, but for what I had to do it was just fine. So say we want to iterate through the returned jQuery Objects using the each method:
(function ($) {
var elms = $('#a-form').find ('input');
elms.each ( function () {
});
})(jQuery);
So how would you use the jQuery Objects that you will iterate through in this code snippet as jQuery DOM Elements? Well there are two ways. You can ether use the this with the $ selector as follows:
(function ($) {
var elms = $('#a-form').find ('input');
elms.each ( function () {
$(this).click ( function () {
//code here
});
});
})(jQuery);
Or you could save the element into a variable for later use like so:
(function ($) {
var elms = $('#a-form').find ('input');
elms.each ( function () {
var elm = $(this);
});
})(jQuery);
Hope this helps someone.
Tags: DOM, JavaScript, jQuery, object
Categories: Articles, JavaScript, Technical, jQuery
Maja Williams has written 16 articles.
Other articles by this author Maja Williams




Thanks man, it did help me a lot.
fyi, you might want to check this method too:
http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx#tip12
by attaching the event to the parent (‘#a-form’ in your example), your code is cleaner and you’re prepared for any possible DOM manipulation as well.
cheers,
Atg