How can I make a jQuery UI button maintain ui-state-active?
I have a button, that I want to be a toggle button. So when I activate it should stay active.
Currently if I set ui-state-active on a button it will get removed if I hover over it.
The markup for the button is just:
this.button = $('<div>')
.html(this.text)
.addClass(this.options.baseClass)
.attr('title', this.getTitle())
.click(this.click.bind(this))
.button();
And the button must be a div, it can’t be a checkbox.
???
Simple workaround
Another suggestion is to use
ui-state-highlightinstead.Manually handle hover
Aside from using a
checkbox&labelcombination instead of adiv, the only workaround I’ve used is to unbindmouseover&mouseoutfrom the button post-initialization, then binding my ownmouseover/mouseoutfunction to the button that handles the toggling ofui-state-hovermyself.