[英]Remove hyperlink but keep text?
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
每當超鏈接的標題為“顯示個人資料”時,我想刪除超鏈接並僅用文本替換它。
所以代替
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
我只想擁有Mentalist
。
知道如何解決這個問題嗎?
要在多個類的鏈接上執行此操作,
$("a.className1, a.className2").contents().unwrap();
這樣做:
<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>
它應該只替換第一個鏈接。
刪除超鏈接但保留文本的香草 JavaScript 方式(而不是 jQuery):
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)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.