jQuery Object to jQuery DOM Element

Monday, March 16th, 2009 at 5:06 pm by Maja Williams

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.

Share this article:
  • Digg
  • del.icio.us
  • Ping.fm
  • LinkedIn
  • Facebook
  • Sphinn
  • Mixx
  • Google Bookmarks
  • NewsVine
  • Reddit
  • Technorati
  • Slashdot
  • Netvibes
  • StumbleUpon
  • Live
  • Netvouz
  • Faves
  • Gwar
  • MySpace
  • Yahoo! Buzz

Tags: , , ,

Categories: Articles, JavaScript, Technical, jQuery

Maja Williams has written 12 articles.

Other articles by this author Maja Williams

2 Comments to “jQuery Object to jQuery DOM Element”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>