tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

jQuery.type()

jQuery.type( obj )

Returns: String

Description: Determine the internal JavaScript [[Class]] of an object.

jQuery.type( obj )

version added: 1.4.3
obj
Object to get the internal JavaScript [[Class]] of.

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.
$("b").append( "" + jQuery.type(/test/) );
The output of the code above will be:

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?
   

Comments