lara336223's avatar

<a> a tag Not working , most Odd :~/

Hello, I have an a tag inside a span that is inside an li that will not work & I cannot for the life of me work out why :~/ !? Any thoughts ? Thank-You Sid

0 likes
3 replies
LaryAI's avatar
Level 58

Certainly! There are a few common reasons why an <a> tag might not work as expected inside a <span> and <li>. Here are some troubleshooting steps and solutions:

  1. Check for Overlapping Elements (CSS/JS):
    Sometimes, CSS or JavaScript might be placing another element over your <a> tag, making it unclickable. Use your browser's developer tools (right-click → Inspect) to see if anything is covering your link.

  2. Pointer Events Disabled:
    If the CSS property pointer-events: none; is applied to the <a>, <span>, or <li>, the link will not be clickable.

    <li>
        <span>
            <a href="https://example.com" style="pointer-events: none;">Click me</a>
        </span>
    </li>
    

    Make sure pointer-events is not set to none.

  3. JavaScript Event Preventing Default:
    JavaScript might be preventing the default action of the link.

    document.querySelector('a').addEventListener('click', function(e) {
        e.preventDefault(); // This will stop the link from working
    });
    

    Check your JavaScript for any event listeners that might be calling e.preventDefault() on the link.

  4. No href Attribute:
    If the <a> tag does not have an href attribute, it will not be clickable.

    <a>Click me</a> <!-- Not clickable -->
    <a href="https://example.com">Click me</a> <!-- Clickable -->
    
  5. HTML Structure:
    The structure you described is valid:

    <li>
        <span>
            <a href="https://example.com">Click me</a>
        </span>
    </li>
    

    This should work unless affected by one of the issues above.

Summary Checklist:

  • Ensure the <a> tag has an href attribute.
  • Inspect for overlapping elements or pointer-events: none;.
  • Check for JavaScript that might be preventing the default action.
  • Validate your HTML structure.

If you post your actual code, I can help debug further!

JussiMannisto's avatar

It should work. Show the code and tell what "not working" means exactly.

1 like
lara336223's avatar

Hello, I found it. I had the css wrong :? The z-index was at fault :/ It was at -1 Should have not been there ! Best Regards Sid

Please or to participate in this conversation.