I created a jQuery user interface button and would like to add a secondary “X” icon to the mouseenter event and remove the “X” from the mouseleave event. That sounds easy.
$("#hover").button({ icons: { primary: "ui-icon-tag" } }).hover(function (event) { // hover in $(this).button("option", "icons", { primary: "ui-icon-tag", secondary: "ui-icon-close" }); }, function (event) { // hover out $(this).button("option", "icons", { primary: "ui-icon-tag" }); });
The freeze event is fired several times if you move the mouse cursor inside the button.
However, it works in Firefox, however it failed with IE and Chrome.
It's hard to explain the fancy effect in words, but see jsFiddle here:
http://jsfiddle.net/27SSr/
My goal is to achieve a consistent effect in all browsers. Thanks =)
EDIT ***
Now I have some tips on why hover over IE and Chrome. Hovering the user interface button several times and checking the button element in Firebug, it turns out that the html tags are corrupted by jQuery UI widgets ..
<button id="hover" class="ui-button ui-widget ui-state-default ui-corner-all ui-state-hover ui-button-text-icons" role="button"> <span class="ui-button-icon-primary ui-icon ui-icon-tag"/> <span class="ui-button-text">Hover me!</span> <span class="ui-button-icon-secondary ui-icon ui-icon-close"/> </button> <span class="ui-button-icon-primary ui-icon ui-icon-tag"/> <span class="ui-button-text">Hover me!</span> <span class="ui-button-icon-secondary ui-icon ui-icon-close"/> </button>
Pay attention to additional SPAN and BUTTON closing tag? Is this behavior a jQuery UI bug?
Here you can try an example:
http://jsfiddle.net/B5sAk/1/