Tuesday, August 14, 2012

Show Tooltip to each element of dropdown

Add following code in master page of your application (make sure you have jquery in your application).

<script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $("select").attr("title", function () {
                return $(this).find("option:selected").text();
            });

            $("select").change(function () {
                $(this).attr("title", function () {
                    return $(this).find("option:selected").text();
                });
            });

            $("select").each(function () {
                var i = 0;
                var s = this;
                for (i = 0; i < s.length; i++) {
                    s.options[i].title = s.options[i].text;
                    // the following  code is not working in IE so added saperate methods above
                   /* if (s.selectedIndex > -1) {
                        s.onmousemove = function () {
                            s.title = s.options[s.selectedIndex].text;
                        };
                    }*/
                }
            });


        });

    </script>