Question

I want to create a jQuery selection that is guaranteed to have no DOM nodes in it. Obviously, I can do this with various hacks, like selecting an id that I know does not exist, but that sucks. How do I do this idiomatically?

Was it helpful?

Solution

This is how you can do this -

var empty = $();

This creates an empty jQuery object:

OTHER TIPS

I never been in this situation but you could use this.

$("<div></div>");

or

var empty = {};

console.log($(empty).attr("id"));

console.log($(empty).text());

console.log($(empty));  

Output:

undefined

""

{"0": {}, "add": function (e,t){var n=typeof e=="string"?v(e,t):v.makeA..................
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top