Search code examples
jqueryhtmlhref

remove attribute HREF after access the LINK


I want to achieve such e effect...

<div id="content"><a href="#MyForm">some text</a></div>

after Clicking/Accessing the Link once to have "some text" as a ordinary text... like

<div id="content"><a>some text</a></div>

So, 1. How to make that LINK first to achieve the result and then TO REMOVE or DISABLE ATTRIBUTE HREFF?

Thank you in advance for your support!


Solution

  • You can rewrite the html element, try this one:

    <div id="content"><a href="#MyForm" onClick="document.getElementById('content').innerHTML='some text';">some text</a></div>
    

    edit: oops on first post, here some explaination.

    By adding the onClick action to remove the element:

    <a href="#MyForm" onClick="document.getElementById('content').innerHTML='some text';">some text</a>
    

    and replace it with

    some text
    

    So after you click the link, you html dom will be modified and look like:

    <div id="content">some text</div>