I have some controls that I need to disable when users don't have edit privileges, but are sometimes not wide enough to show the entire text of the selected option element. In which case I've added a tool tip with ASP.NET and the following code
ddl.Attributes.Add("onmouseover", "this.title=this.options[this.selectedIndex].title")
This works when the control is enabled, but doesn't work when it is disabled.
The following alert will not fire when a mouse is over the select element:
<select disabled="disabled" onmouseover="alert('hi');">
<option>Disabled</option>
</select>
See this fiddle.
Q: Can I fire the onmouseover
event for controls that are disabled
?
The Onmouseover event handler in Javascript is an event handler that is triggered when a user places the cursor of a mouse over an element. This can be any HTML element, such as a link, an image, a paragraph, a header, etc.
Solution: To disable the display of hover text for a link, perform the following steps: From the Service Desk tab, click on the View pull-down and then click on Preferences. In the General settings, check the option "Disable Mouseover Previews" as shown in Figure 1.
The onmouseover event attribute works when the mouse pointer moves over the specified element. Attribute value: This attribute contains single value script which works when mouse moves over the element.
Definition and UsageThe onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.
Disabled elements do not fire events, e.g. users cannot hover or click them to trigger a popover (or tooltip). You can however wrap the disabled element with a DIV
and listen to the event fired on that element instead.
Update: Please see nathan william's comment for some serious limitations to this approach. I've updated the fiddle to illustrate the problem areas more clearly.
Expanding on what @Diodeus said, you can use jQuery to automatically create the div
container for you and wrap it around any disabled elements.
:disabled
selector to find all disabled elements..wrap()
method with a function callbackthis
to refer to the current element in the set..attr()
method to get the onmouseover
value from the parent element and apply the same value to the new div.$(':disabled').wrap(function() {
return '<div onmouseover="' + $(this).attr('onmouseover') + '" />';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With