Issue #2749💬 AnsweredOpened April 30, 2020by HansSchouten0 reactions

Disable hyperlink preventDefault()

快速解答by HansSchouten

I solved it for now by adding an additional script to the component to listen for clicks on the li, which triggers directly the tab('show') call on the a.

Read full answer below ↓

Question

By default all html anchor elements have their click behaviour disabled (which is very useful of course). However, I would like to make elements editable that requires some javascript behaviour on hyperlinks to still pass through. For example, editing the content of the various panels in a bootstrap tabs navbar: afbeelding

I have found the following code snippets that set the related preventDefault() behaviour: FrameView and ComponentLinkView.

I tried unsetting the registered click events after loading GrapesJS using removeEventListener, but currently without any luck. Are there any suggestions on what I can try to disable this preventDefault() behaviour on specific elements. Or is it an idea to add the preventDefault only on elements with a href that does not start with a # for example?

Answers (1)

HansSchoutenMay 5, 2020

I solved it for now by adding an additional script to the component to listen for clicks on the li, which triggers directly the tab('show') call on the a.

$(document).find("li.nav-item").click(function() {
    $(this).find('a').tab('show');
})

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.