views:

233

answers:

4

I have to implement the tooltip feature for drop down. Also, tooltip will not be any static text, it should be the selected value of drop down. How can i do this in jQuery?

A: 

You can implement the dropdown in javascript as a div. Once you do that, you can add the tooltips using something like: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/

Ralph Stevens
is there any other approach instead of creating the div for drop down
Rakesh Juyal
A: 

Something like this ?

selectElement.addEventListener('change', function (e) {
  selectElement.title = selectElement.value;
});
Alsciende
Alsciende, this is not what i was expecting. :). Tooltip must be displayed in nice way. The title shown by browser doesn't look good. Tooltip: http://dev.mariusilie.net/content/simple-tooltip-jquery-plugin
Rakesh Juyal
Well, I guess you can call you own tooltip-api instead of ".title".
Alsciende
A: 

I got the soultion:

Just in case you wanted to know how i did that:-

jQuery('#myDropDownID').hover(function(e){
                var tipX = e.pageX + 12;
                var tipY = e.pageY + 12; 
                jQuery("body").append("<div id='myTooltip' class='portal-tool-tip' style='position: absolute; z-index: 100; display: none;'>" + jQuery("OPTION:selected", this).text()  + "</div>");
                if(jQuery.browser.msie) var tipWidth = jQuery("#myTooltip").outerWidth(true)
                else var tipWidth = jQuery("#myTooltip").width()
                jQuery("#myTooltip").width(tipWidth);
                jQuery("#myTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
            }, function(){
                jQuery("#myTooltip").remove();              
            }).mousemove(function(e){
                var tipX = e.pageX + 12;
                var tipY = e.pageY + 12;
                var tipWidth = jQuery("#myTooltip").outerWidth(true);
                var tipHeight = jQuery("#myTooltip").outerHeight(true);
                if(tipX + tipWidth > jQuery(window).scrollLeft() + jQuery(window).width()) tipX = e.pageX - tipWidth;
                if(jQuery(window).height()+jQuery(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
                jQuery("#myTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
            });

See here: http://jsbin.com/owoka

Rakesh Juyal