Disable tooltips using css

后端 未结 10 977
隐瞒了意图╮
隐瞒了意图╮ 2021-02-12 15:33

Is there a way to disable the tooltips of the tag in css?

10条回答
  •  盖世英雄少女心
    2021-02-12 16:02

    Unfortunately there is no pure CSS solution. If anyone looking for a DOM only solution (without jQuery)

    document.querySelectorAll('a[href]').forEach(el => {
      el.setAttribute('data-title-cache', el.textContent.trim() || el.getAttribute('href'));
      el.setAttribute('title', el.getAttribute('data-title-cache'));
      el.addEventListener('mouseenter', (e) => {
        el.setAttribute('title', '');
      });
      el.addEventListener('mouseleave', (e) => {
        el.setAttribute('title', el.getAttribute('data-title-cache'));
      });
    });
     This is a link 

    You just have to paste this code. The script sets the title from the text content or the href found in the a tag. Then removes the title attribute on mouse hover. So that the default browser tooltip would not be displayed on hover.

    The link in the code snippet has a title but the tooltip won't be displayed on hover. (Inspect and check)

提交回复
热议问题