Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Disable all links within a div - replace with inner content

Tags:

jquery

I want to disable all links within a div and replace it with the content that was there.

i.e.

<div><a href="/blah.html">My super link</a></div>

to

<div>My super link</div>

Thanks

like image 499
Chris Avatar asked Jan 20 '26 00:01

Chris


1 Answers

You can do it using .replacewith() and a function, like this:

​$("div a").replaceWith(​​​​function() { return $(this).text();​ });​

You can see a quick demo here

like image 71
Nick Craver Avatar answered Jan 21 '26 19:01

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!