<div class="test one">aaa</div> <div class="test two">bbb</div> <div class="test three">ccc</div>
Is possible change order this divs with jQuery? I would like receive:
<div class="test two">bbb</div> <div class="test three">ccc</div> <div class="test one">aaa</div>
i can use only jQuery
LIVE: http://jsfiddle.net/cmVyM/
I will make this only one - if document is ready.
To change order of divs with jQuery, we can use the insertAfter method. to add 3 divs. Then we take the first div and insert it after the 3rd with: const tests = $('.
If you need to completely replace the HTML content of the div , use the innerHTML property. Copied! const div = document. getElementById('container'); // ✅ Change (replace) the text with HTML div.
Sounds like you want to move the first div after the last.
$.fn.insertAfter
inserts the matched elements after the parameter:
$(".test.one").insertAfter(".test.three");
http://jsfiddle.net/rP8EQ/
Edit: If you want a more general solution of adding the first to last, without resorting to the explicit classes:
var tests = $('.test'); tests.first().insertAfter(tests.last());
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