Is there any way to find all numeric classes with jQuery?
I have elements with the following classes:
<div class="placeholder 0 original dropped default-load"></div>
<div class="placeholder 1 original dropped default-load"></div>
<div class="placeholder 2 original dropped default-load"></div>
<div class="placeholder 3 original dropped default-load"></div>
But, I'm using jQuery draggable ui. So those placeholders are draggable, and eventualy those numeric classes will be in a random order eg (3, 0, 2, 1), and will no longer match with the index
if I use the .each
function.
So basicly, on pageload, the elements will have the order as 0, 1, 2, 3, ... (based on amount of results in the database).
They can mess around and this will result in a random order (0, 3, 2, 1, ...). But there is a default button. With this button they can undo all there actions, and reset the default order.
I tried with the following but this didn't work as the index
doesn't match with the numeric class if they mess around (which they will obviously will).
$(".default").click(function (e) {
e.preventDefault();
$("li.placeholder").each(function (index) {
$(this).empty();
$(this).removeClass(index);
$(this).removeClass("dropped");
$(this).removeClass("default-load");
if (!($(this).hasClass("original"))) {
$(this).remove();
}
$(".modal-" + index).remove();
});
init(); // Callback
});
Any help is greatly appreciated!!