jQuery checking if a selector worked or is valid

So if a jQuery selector failed to match it used to return the document at the root level of the DOM. Now it will return an empty set. What is an empty set? If you do var test = jQuery(); you’ll get the thing — an empty jQuery wrapper object that appears around every selected element when using jQuery selectors.

So, if you do $(‘#bogusId)’, you should get a jQuery object with a length of zero. I think that is the best way I have seen to tell if nothing was matched, just check for a length of zero on the result of calling something that doesn’t match.

if($(‘#bogusID’).length ==0)


var myjQueryElement = $(‘#bogusID’);
if(myjQueryElement.length == 0 )

You can also use size()

See http://api.jquery.com/jQuery/

‘As of jQuery 1.4, calling the jQuery() method with no arguments returns an empty jQuery set. In previous versions of jQuery, this would return a set containing the document node.’

gem install rails on VirtualBox Ubuntu guest on a Windows 7 host times out

Apparently if you have the network interface as NAT (the most standard one) then the gem installer has issues connecting to remote sources. Use a bridged network connection, or download all the gems you need separately for rails, and install each using the gem install GEMNAME –local command in the folder where you download the gems. (I couldn’t get the bridged connection to work either, so I just installed all the gems by downloading each gem separately. Sort of annoying, but once you know how to do it, and what the dependencies are (rails has sort of a lot, but not too bad), it is easy. Use rubygems.org and not rubyforge.org)

This is weird since other remote gems work fine. The link at the bottom discusses how this might be a bug or something. Very annoying though, getting to the point where you find that it isn’t a linux problem, but a virtualbox and rubygems thing.

To get to the nitty gritty you have to do sudo gem install -V –debug (for verbose debugging).

The first level of error, by using the -V verbose option will show
Error fetching remote data: timed out (on some remote gem), and then eventually the non-verbose error:

ERROR: While executing gem … (Gem::RemoteFetcher::FetchError) timed out (http://rubygems.org/gems/rails-x.x.x.gem)

To get to the root of the problem, you use the –debug flag which will show

Exception `NameError’ at YOURENV/command_manager.rb:161 – uninitialized constant
Exception `Gem::LoadError’ at YOURENV
rubygems.rb:826 – Could not find RubyGem sources (> 0.0.1)
Exception `Errno::ETIMEDOUT’ at YOURENV/net/

See http://www.ruby-forum.com/topic/204146