Skip to content

Instantly share code, notes, and snippets.

View devonkinghorn's full-sized avatar

Devon Kinghorn devonkinghorn

  • Atomic
  • Draper Ut.
View GitHub Profile
@ronmichael
ronmichael / getTextBoundingRect.js
Created September 6, 2013 22:01
Get the bounding box coordinates of the actual text within an HTML input box
// http://stackoverflow.com/questions/6930578/get-cursor-or-text-position-in-pixels-for-input-element/7948715#7948715
function getTextBoundingRect(input, selectionStart, selectionEnd, debug) {
// Basic parameter validation
if (!input || !('value' in input)) return input;
if (typeof selectionStart == "string") selectionStart = parseFloat(selectionStart);
if (typeof selectionStart != "number" || isNaN(selectionStart)) {
selectionStart = 0;
}