Remove hyperlink but keep text?

后端 未结 4 1361
挽巷
挽巷 2020-12-09 08:07
Mentalist

Whenever a hyperlink has a title of \"Show Profile\"

相关标签:
4条回答
  • 2020-12-09 08:24

    this should work:

    $('a[title="Show Profile"]').contents().unwrap();
    

    Here a Fiddle with the proof.

    0 讨论(0)
  • 2020-12-09 08:28

    This will do:

    <a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
    <a href="http://www.website.com/something" title="Something Else">Mentalist</a>
    
    <script type="text/javascript">
    $("a[title='Show Profile']").each(function(){
        $(this).replaceWith($(this).text());
    });
    </script>
    

    It should replace only the first link.

    0 讨论(0)
  • 2020-12-09 08:37

    Vanilla JavaScript way (instead of jQuery) to remove hyperlink but keep text:

    const links = document.querySelectorAll('a[title="Show Profile"]')
    
    links.forEach(link => {
        const el = document.createElement('span')
        el.textContent = link.textContent
        link.parentNode.replaceChild(el, link)
    })
    
    0 讨论(0)
  • 2020-12-09 08:45

    To do this on links of multiple classes,

    $("a.className1, a.className2").contents().unwrap();
    
    0 讨论(0)
提交回复
热议问题