This code works perfect for sorting a dynamically created div:
<div id='1'>a</div>
<div id='2'>b</div>
<div id='3'>c</div>
<div id='4'>d</div>
<div id='5'>e</div>
<div id="addnew">Add New</div>
$('#addnew').live('click',function() {
newdiv = $("<div id='4'>AA</div>");
div_id_after = Math.floor(parseFloat(newdiv.get(0).id));
$('#'+div_id_after).after(newdiv);
});
All I want to do is take this same function and make it work to use a custom attribute “data-sort=” rather than ID.
Regards
just use newdiv.attr(‘data-sort’) to access custom attribute of your div
UPDATE:
Indeed if you later want to iterate over all div elements and use the ‘data-sort’ attribute for sorting, using jQuery you would do something like: