I have three divs like below
<div class="col-lg-4"> A</div>
<div class="col-lg-4"> B </div>
<div class="col-lg-4"> C </div>
Basically for xs devices, it becomes like
A
B
C
However, I want it like
A
C
B
How can I do that?
I have three divs like below
<div class="col-lg-4"> A</div>
<div class="col-lg-4"> B </div>
<div class="col-lg-4"> C </div>
Basically for xs devices, it becomes like
A
B
C
However, I want it like
A
C
B
How can I do that?
Use JavaScript sort()
function:
Example: (do not copy/paste)
var obj = [];
var example = ["A", "C", "B"];
$.each($("div"), function(index, value) {
obj[index] = $(this);
});
obj.sort(function(a, b) {
var A = example.indexOf(a.text().trim());
var B = example.indexOf(b.text().trim());
if (A < B) {
return -1;
}
if (A > B) {
return 1;
}
return 0;
});
$("body").prepend(obj);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-lg-4"> A</div>
<div class="col-lg-4"> B </div>
<div class="col-lg-4"> C </div>
Use it to learn not to copy ;-)
In bootstrap this is easy to solve this in html:
<div class="row">
<div class="col-lg-4 col-xs-12"> A</div>
<div class="col-lg-4 col-lg-push-4 col-xs-12"> C </div>
<div class="col-lg-4 col-lg-pull-4 col-xs-12"> B </div>
</div>
You can order your divs with css Using the order property.
<div class="col-lg-4" id="A"> A</div>
<div class="col-lg-4" id="B"> B </div>
<div class="col-lg-4" id="C"> C </div>
The CSS
#A{order:1;}
#B{order:3;}
#C{order:2;}
If you want that for different screen size to be something else just use media queries!