views:

487

answers:

3

Sometimes it is useful to have an empty jQuery object, to be used either as a default value or as an initial value, when constructing a collection of items.

For an example, see here.

One way to do it would be to use a selector which is unlikely to match anything, like $('skdhjfksjdhfksjhdf'), but this is obviously inelegant.

How can I get an empty jQuery object in elegant style ?

+1  A: 

Do you mean...

//just get jQuery...
var foo = $();

//or just get the browser using jQuery...
if($.browser.msie){
  alert('You are using the blue e!');
}
scunliffe
or `$.ajax` or...
geowa4
+1  A: 
  1. sorry for trouble - $([]) worked quite good
  2. I need empty selector to poplate it with specific nodes in .each loop
Peter Kaleta
+1  A: 

Starting with jQuery 1.4, a simple $() will return an empty set. jQueery 1.4 release notes ("jQuery() returns an empty set").

For earlier versions, use $([])

itsadok