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,772
  • 7
  • 31
  • 48
nicholaswmin
  • 19,740
  • 13
  • 80
  • 155

3 Answers3

2

jQuery:

$( 'whatever selects your link' ).on( 'click', function( ev ){
    ev.preventDefault(); // stop click event
    $( this ).trigger( 'hover' );
} );
None
  • 1
  • 30
  • 155
  • 213
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
  • 40,889
  • 58
  • 100
  • 149
0

Use the below script and trigger hover event

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