Switch positions of 2 divs with jQuery

后端 未结 6 1639
遥遥无期
遥遥无期 2020-12-02 22:45

I\'m wondering if it\'s posible to switch positions of two divs with jQuery.

I have two div like this

STUFF ONE
6条回答
  •  一向
    一向 (楼主)
    2020-12-02 23:26

    Well ... why are you trying to change the POSITION of the div elements. Does it matter? Why not changing the CONTENT?

    var divOneText = $('#div1').html();
    var divTwoText = $('#div2').html();
    
    if (divOneText != '' && divTwoText != '') {
      $('#div1').html(divTwoText);
      $('#div2').html(divOneText);
    }
    

    Add trim() if you want to remove whitespace.

提交回复
热议问题