Created
December 7, 2015 15:56
-
-
Save williamdodson/eadfce84482b30414567 to your computer and use it in GitHub Desktop.
jQuery plugin to return a given input type as a string (e.g. "textarea").
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function getInputType | |
* | |
* @return String name for the type of input (i.e. select or textarea) | |
* @example <code>var inputType = $(input).getInputType(); // returns a string representation of the given input</code> | |
* @author William Dodson <[email protected]> | |
* @version 1.0.0 | |
*/ | |
(function ($) { | |
'use strict'; | |
$.fn.getInputType = function () { | |
var inputType; | |
// return early if we get passed an undefined field name | |
if(typeof this[0] === 'undefined') { | |
return; | |
} | |
inputType = this[0].tagName.toString().toLowerCase() === 'input' ? | |
$(this[0]).prop('type').toLowerCase() : this[0].tagName.toLowerCase(); | |
return inputType; | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment