How to sort a random div order in jQuery?

后端 未结 4 1065
轻奢々
轻奢々 2021-01-07 14:20

On page load, I am randomizing the order of the children divs with this Code:

function reorder() {
   var grp = $(\"#team-posts\").children();
   var cnt = g         


        
4条回答
  •  天涯浪人
    2021-01-07 14:59

    Just give each item a class with the corresponding order and then get the class name of each div and save it to a variable

    $("#team-posts div").each(function() {
        var parseIntedClassname = parseInt($(this).attr("class");
        arrayName[parseIntedClassname] = $("#team-posts div." + parseIntedClassname).html()
    });
    

    You can reorder them from there by saving their html to an array in order

    $("#team-posts").html();
    for(var i=0;i'+arrayName[i]+'
    '); }

提交回复
热议问题