« Return to Thread: Creating an empty jQuery object

Re: Creating an empty jQuery object

by wycats :: Rate this Message:

Reply to Author | View in Thread

You know that you can create a DOM Element by doing $("<div></div>"), right? I think that might be a better way to achieve what you're trying to achieve, but I'm not sure. :(

I think $([]) is currently the most elegant way to get an empty object, but this is definitely something that should be pointed out front-and-center.

-- Yehuda

On 2/16/07, Danny Wachsstock <d.wachss@...> wrote:

I've been using jQuery for a few months now, trying to convert all my
hand-rolled javascript and came across a minor problem that I could not find
documented anywhere:
I want to create DOM elements and add them into a jQuery object, as in;

var result = [empty jQuery object];
$.each(...
  var element = ...;
  result.add(element);
);

But how to create an empty jQuery? Scouring the source code, I eventually
hit upon $([]), but this is nowhere documented. Is there a better way?
Is there a good reason $() should return $(document) rather than an empty
jQuery?

Daniel Wachsstock
http://youngisrael-stl.org

--
View this message in context: http://www.nabble.com/Creating-an-empty-jQuery-object-tf3240592.html#a9008167
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@...
http://jquery.com/discuss/



--
Yehuda Katz
Web Developer | Wycats Designs
(ph)  718.877.1325
_______________________________________________
jQuery mailing list
discuss@...
http://jquery.com/discuss/

 « Return to Thread: Creating an empty jQuery object