Reordering of Divs

后端 未结 6 781
轮回少年
轮回少年 2020-12-03 01:23

How would I go about reordering divs without altering the HTML source code?

example, I want divs to appear in order #div2, #div1, #div3, but in the HTML they are:

6条回答
  •  难免孤独
    2020-12-03 01:56

    You could do, in Javascript:

    function reOrder() {
      divOne = document.getElementById('#div1');
      divTwo = document.getElementById('#div2');
      divThree = document.getElementById('#div3');
      container = divOne.parentNode;
      container.appendChild(divTwo);
      container.appendChild(divOne);
      container.appendChild(divThree);
    }
    

    Edit: Fixed typo in IDs.

提交回复
热议问题