Search code examples
jqueryjquery-selectorsidentityempty-list

jQuery: how do I select no elements?


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?


Solution

  • This is how you can do this -

    var empty = $();
    

    This creates an empty jQuery object: