Close Content Off Canvas on click or touch

Hi,

I have added the ‘content area off canvas’ element to my menu.
I have anchor links within the off canvas content.

How do I get the off canvas toggle to close when clicking on an anchor link on the same page?

You can see my example here: https://www.brainglish-intlschool.com/unique-programs/

I have an anchor link here: https://www.brainglish-intlschool.com/unique-programs/#english-in-nature/

It will not close the menu when I click it. I have tried this JS and it does not work:

$(’.e3219-4.x-off-canvas .x-off-canvas-content .x-anchor’).on( “click touchstart”, function() {
if ($(this).attr(‘href’).indexOf(’#’) !== -1) {
$(’.x-off-canvas-close’).click();
}
});

Hello Can,

Thank you for the details. I have checked your page and your code. There seems to be a problem with your code because it is incorrect. Please have it updated and use this instead:

(function($){
	$('.e3219-4.x-off-canvas .x-off-canvas-content a').on( "click touchstart", function() {
		if ($(this).attr('href').indexOf('#') !== -1) {
			$('.x-off-canvas-close').click();
		}
	});
})(jQuery);

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer.

Regards.

That worked perfectly! Thank you so much!!!

You’re most welcome, Can.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.