In this article I will explain with an example, how to use Enum (Enumeration) with jQuery.
 
 
Using Enum (Enumeration) with jQuery
A simple Enum of 3 colors Red, Green and Blue to which I have assigned integer values 1, 2 and 3 respectively.
The following HTML Markup consists of an HTML Select DropDownList. The HTML Select DropDownList has been assigned a jQuery change event handler, when the DropDownList is changed the selected value is compared with the Enum and the respective color is displayed using JavaScript alert message box.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        var colors = { "Red": 1, "Green": 2, "Blue": 3 };
        $(function () {
            $("#ddlColors").change(function () {
                switch (parseInt($(this).val())) {
                    case colors.Red:
                        alert("Red");
                        break;
                    case colors.Green:
                        alert("Green");
                        break;
                    case colors.Blue:
                        alert("Blue");
                        break;
                }
            });
        });
    </script>
</head>
<body>
    <select id = "ddlColors">
        <option value="1">Red Color</option>
        <option value="2">Green Color</option>
        <option value="3">Blue Color</option>
    </select>
</body>
</html>
 
 
Screenshot
Using Enum (Enumeration) with jQuery
 
 
Demo
 
 
Downloads