Attempting to condense some of the coding on a website I’m now looking after and was wondering if there is a more efficient way of writing the following coding as I realise there is doubling up of information.
$("span.menu-link-title.active-components").mouseover(function(){$('#active-components-image').css('display', 'block');});
$("span.menu-link-title.active-components").mouseleave(function(){$('#active-components-image').css('display', 'none');});
$("span.menu-link-title.adaptors").mouseover(function(){$('#adaptors-image').css('display', 'block');});
$("span.menu-link-title.adaptors").mouseleave(function(){$('#adaptors-image').css('display', 'none');});
You can use
hoverandtogglemethods:hoveris a shorthand formouseenter(not mouseover) andmouseleaveevents and it also accepts 2 functions. You can also cache the objects.