added check for jQuery to the snippet to prevent hidden bug when jQuery is not set in jsfiddle.net