0

I am working with a CMS that doesn't allow me much to do in terms of editing their code.


I have this element:

<a href="/development/tomato_site/" title="SampleTitle"
 class="menu_icon menu-641 sf-depth-1 menuparent" > Tomatos </a>

When hovering over this link something pops up which is set through the CMS.

I want on clicking the element, the hover event to happen instead of going to the actual href link.

Is this possible to do via jQuery? Maybe dispatch a click event as a hover event?

MH2K9
  • 11,951
  • 7
  • 32
  • 49
nicholaswmin
  • 21,686
  • 15
  • 91
  • 167

3 Answers3

2

jQuery:

$( 'whatever selects your link' ).on( 'click', function( ev ){
    ev.preventDefault(); // stop click event
    $( this ).trigger( 'hover' );
} );
2

You can certainly prevent the default action of clicking and trigger the hover event instead, but I wouldn't recommend it due to accessibility and usability concerns.

$('a').click(function(e) {
    e.preventDefault();
    $(this).trigger('hover');
});

(Here I'm using a as the selector but you probably want to be way more specific as to which links you are selecting.)

If the current hovering effect is done via CSS :hover pseudo-class, this will not have the desired outcome.

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
0

Use the below script and trigger hover event

$( '.menu_icon' ).click(function(){
 $(this).trigger('hover');
 return false;
});
karan3112
  • 1,867
  • 14
  • 20