Reordering of Divs

后端 未结 6 780
轮回少年
轮回少年 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:55

    I would use Javascript to traverse the nodes accordingly. If you want to use a library like jQuery, you can use the above suggestions. If you'd prefer not to have the bloat, use the following simple and minimalistic solution...

    
    
    
      
        Test
        
        
      
      
        
    1
    2
    3

    Best regards...

    EDIT: Changed function name from swapNode to swapSibling, as I am fairly certain this will only work with nodes that have the same parent.

提交回复
热议问题