I have the following code, its supposed to reorder my divs within #list. And it does that just fine. Now what I want to add is: if a div does not have the attribute "data-l-disc" don't add it/hide it.
<select id="selectid">
<option id="valid1" value="def">Default order</option>
<option id="valid2" value="hl">h-l</option>
</select>
<div id="list">
---------the follow div is used about 50*-------------
<div class="dbl" data-l-disc="1">
---------blabla (like 10 other divs are in here)----------
</div>
</div>
jQuery(document).ready(function( $ ) {
$('select').on('change', function() {
if(document.getElementById('selectid').value == "hl") {
var dList = $(".dbl");
dList.sort(function(a, b){ return $(b).data("l-disc")-$(a).data("l-disc")});
$("#list").html(dList);
}
})
});
<div>is a tag; if you had the tag<div data-l-disc="something">, thedata-l-disc="something"part is an attribute.#listwould help in answering your question.