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?
To essentially disable it, you could likely do: $("a[href='http://www.google.com']").click(function(e) { e. preventDefault(); });
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.
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 .
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.
Alternate solution:
$("a#link").replaceWith($("a#link").text());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With