Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery replace multiple elements using class

Tags:

jquery

I want to replace all the spans with a div. When I run this code only one element gets replaced. How to change this code so that the script affects all the spans?

I have tried to use clone(), but it didn't work.

$flexBox = $("<div></div>");
$(".overlayBox").replaceWith($flexBox);

<span class="overlayBox"></span>
<span class="overlayBox"></span>
<span class="overlayBox"></span>
like image 453
Registered User Avatar asked Feb 19 '26 06:02

Registered User


1 Answers

You can use replaceAll() method:

$flexBox.replaceAll(".overlayBox");​

DEMO: http://jsfiddle.net/4VHVC/

like image 148
VisioN Avatar answered Feb 20 '26 19:02

VisioN



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!