jQuery.type( obj )
Returns: String
Description: Determine the internal JavaScript [[Class]] of an object.
A number of different aspects are utilized to determine the exact return value for an object. The logic can be determined as follows:
- If the object is undefined or null then "undefined" or "null" is returned accordingly.
- If the object has an internal [[Class]] equivalent to one of the browser's built-in objects we return the associated name. (More details about this technique.)
- jQuery.type(true) === "boolean"
- jQuery.type(3) === "number"
- jQuery.type("test") === "string"
- jQuery.type(function(){}) === "function"
- jQuery.type([]) === "array"
- jQuery.type(new Date()) === "date"
- jQuery.type(/test/) === "regexp"
- Everything else will return "object" as its type.
Examples
Finds out if the parameter is a RegExp.Full source:
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.5.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> $(document).ready(function(){ $("b").append( "" + jQuery.type(/test/) ); }); </script> </head> <body> Is it a RegExp? <b></b> </body> </html>
Was this information helpful?

