My goal is to have a div display on hover, which is currently working fine. However, I also want to add a class when a user clicks on an anchor tag to keep the div visible even after the mouse leaves it. The class should be removed if the user clicks on the anchor tag again or hovers over another div.
$('#main-menu a').mouseover(function() {
var $this = $(this);
var id = $this.attr('rel');
var $currentWidget = $('#' + id);
$currentWidget.show().siblings('.widget-container').hide();
});
$('#wrap').mouseleave(function() {
$('.widget-container').hide();
});
$('#main-menu a').click(function() {
var $this = $(this);
var id = $this.attr('rel');
var $currentWidget = $('#' + id);
$currentWidget.addClass('active').siblings('.widget-container').hide();
});
$('#wrap').mouseleave(function() {
$('.widget-container').hide();
});
To see it in action, click here: Fiddle