Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove anchor tags using jQuery

Tags:

jquery

My html:

<div class="example">
   <a id="link" href="http://www.google.com">Example</a>
</div>

jQuery

$('a#link').remove();

What I would like to do, is make the html look like this after the <a> tag is removed:

<div class="example">
  Example
</div>

How do I remove just the

<a> </a> 

part?

like image 775
cusejuice Avatar asked May 07 '12 20:05

cusejuice


People also ask

How to disable anchor tag using jQuery?

To essentially disable it, you could likely do: $("a[href='http://www.google.com']").click(function(e) { e. preventDefault(); });

How do I turn off anchor tags?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.

How to use jQuery remove?

Use . remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use .

How does jQuery remove work?

The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events of the selected elements. Tip: To remove the elements without removing data and events, use the detach() method instead.


1 Answers

Alternate solution:

$("a#link").replaceWith($("a#link").text());
like image 196
Elliot Bonneville Avatar answered Oct 11 '22 23:10

Elliot Bonneville