The hover
event has actually two states, in other words, for the hover
event there are two different events are used behind the scene and these are mouseenter
and mouseleave
so when you hover over an element the mouseenter
event gets fired and on hovering off the element the mouseleave
event gets fired, so in this case, you can't convert this event to click
using two methods like hover
instead, you just declare one click
event handler (function) for that element. For example, you may do something like this:
$('#element').on('click', function(e){
//...
});
If you want to change the state of the element when another element gets clicked then you should catch the click event for that element so clicking on tnother element you may do the opposite thing. For example, you may register a click event on $('body')
so when click happens on the body
then you may do the opposite thing.