Wednesday, 21 August 2013

How do I get the value of the current select option in a jQuery UI tooltip?

How do I get the value of the current select option in a jQuery UI tooltip?

In jQuery, I am trying to get the value of the 'val' attribute of the
currently selected item in a select box, use that value to retrieve data
and then display that data using a tooltip.
For testing purposes, when I run the following it gets the value just fine
and works as expected:
$( 'select' )
.mouseover( function(){
alert( $(this).val().trim() );
})
More, the following also works fine with a hardcoded parameter value:
$( 'select' ).tooltip({
content: cellTooltipContent( '865' )
});
But when I try something like the following, Chrome Developer tools says
that the parameter to the cellTooltipContent function is undefined.
$( 'select' ).tooltip({
content: cellTooltipContent( $(this).val() )
});
and this doesn't work either:
$( 'select' ).tooltip({
content: cellTooltipContent( $(this).find(':selected').text() )
});
It seems to think that this refers to document rather than the currently
selected item. I've also tried this.val for the parameter, and a few dozen
other things. I've worked on this for three days and I'm completely stuck.

No comments:

Post a Comment