1

I want to enable link using CSS but still enable title. Here is my code:

CSS and HTML Code:

.disabledLink {
   pointer-events: none;
   opacity: 0.6;
   cursor: default;
 }
<a href="www.google.com" class="disableLink" title="My Title" /> 
  <span datahover="test">My Link</span> 
</a>

Unfortunately, title is not appearing when hovering my mouse to the link. Is there a better way to enable title?

4
  • do you want title for that link Commented Oct 6, 2016 at 9:44
  • what are you trying to achieve because if you simply want to show hover text title attribute should be enough.... Commented Oct 6, 2016 at 9:46
  • 1
    Javascript - From a comment in a related link... "Use of pointer-events: none; is not perfect. It also disables other events such as hover, which is required for display of title="…" or tooltips. I found the JS solution is better (using event.preventDefault();" Commented Oct 6, 2016 at 9:46
  • If only title is needed then use span tag and add a title attribute to it. Rest of the designs can be attained by CSS also like <span class="look-like-link" title="My Title">My Link</span> and .look-like-link{ text-decoration: underline; color: blue} Commented Oct 6, 2016 at 9:52

2 Answers 2

19

.disabled-link {
  pointer-events: none;
}
<span datahover="test" title="My Title"><a href="www.google.com" class="disabled-link">My Link</a></span>

Change your markup into this. It will work. Instead of targeting <a> tag, I target the span for title. Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

You should put your span tag inside the link tag, like this:

<a href="www.google.com" class="" title="My Title"> <span datahover="test">My Link</span> </a>

1 Comment

How would this work...since pointer-events are disabled for the whole link? And ths is exactly what the OP is already doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.