I've noticed 3 scenarios relating to links in the customizer preview frame.
1) Clicking a link to an external url does nothing. This is good.
2) Clicking a link to a same origin/domain url results in refreshing the customizer preview with that url's content. Again, good.
3) Clicking on a link with a hash or anchor tag refreshes the customizer preview and whether or not you happen to be customizing the site's home page, that is where you end up unless you refresh the browser to get back to customizing the page/post you were originally at.
When wanting to style a mobile menu for example, the classic "hamburger" element uses an anchor tag that triggers this undesired refresh. I want to be able to reveal the menu just as the click event would on the published front-end and then use my nifty customizer tools to style my menu that my plugin allows for.
Other elements also come in to play, such as icons, tabs and other subtle front-end click animations that "reveal" additional content on the page.
For example, this could be a theme's code that would exploit this behavior:
<a href="#" class="show-me"> <i class="some-nifty-icon-gizmo-that-animates-into-view"></i> </a>
Is there a way to unbind this baked-in click event listener on a per element basis?
I've tried the usual event.preventDefault and event.stopPropagation to get around this but no luck so far. I've also tried the jQuery "off" and "unbind" methods but can't seem to nail it.
It looks like it's coming from /wp-includes/js/customize-preview.min.js and all anchor tag click events bubble up to the body element.
A way around this at the moment is to manipulate the DOM via browser inspector to add whatever class or css is needed that the original click event would have completed.
Edit: Please, this is not about theme coding standards and semantics, the examples provided above are just that, examples of which any and all plugins could run into. While I necessarily wouldn't use an anchor tag for a menu button, we (as software developers) still have to plan for these things.