Skip to content

Instantly share code, notes, and snippets.

@nicbell
Created March 5, 2013 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicbell/5090022 to your computer and use it in GitHub Desktop.
Save nicbell/5090022 to your computer and use it in GitHub Desktop.
The purpose of this plugin is to be able to detect if a point (X,Y) falls within an element.
(function ($) {
$.fn.hitTest = function (x, y) {
return (x > this.offset().left && x < this.offset().left + this.width()) && (y > this.offset().top && y < this.offset().top + this.height());
};
})(jQuery);
var isHit = $(".something").hitTest(90, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment