I have an icon name tag-icon-arrow
i have onclick and hover events on it.
But since i hover over the icon the hover is active and when clicked both are active which i don’t want, I know before clicking it will hover here,but if i click on the icon it should turn off.
bindViewEvents: function () {
let me = this
, window = this.$window
, $tagArrow = window.find(".tag-icon-arrow");
$tagArrow.off().on('click', function (e) {
me.highlight(e, true, true);
});
$tagArrow.hover(
function (e) {me.highlight(e, true);},
function (e) {me.highlight(e, false);}
);
$tagArrow.on('click', function (e) {
me.selectRole(e);
});
},
Here you can see hover is always active since its depends on cursor.
How can improve this so that both work properly? as they are expected to.
2
Answers
The easiest way to do this is to use a flag that says whether the icon has been clicked or not, and then use that flag to conditionally turn on/off the hover effect.
Here’s the code:
Just don’t turn off highlighting when the role is selected:
But better use CSS: