Any way to shuffle content in multiple div elements

前端 未结 8 1109
鱼传尺愫
鱼传尺愫 2020-12-31 23:32

I\'m relatively new to Javascript and was wondering if there\'s a quick way to shuffle content that is contained in multiple

tags. For example

8条回答
  •  既然无缘
    2021-01-01 00:28

    You can grab the content of each div

    c1 = document.getElementById('div1').innerHTML
    c2 = document.getElementById('div2').innerHTML
    c3 = document.getElementById('div3').innerHTML
    

    Then determine a new order for them randomly .. and then put each content in the new destination

    say for instance, the randomness gave:

    c1_div = 'div2'
    c2_div = 'div1'
    c3_div = 'div3'
    

    then you just:

    document.getElementById(c1_div).innerHTML = c1
    document.getElementById(c2_div).innerHTML = c2
    document.getElementById(c3_div).innerHTML = c3
    

提交回复
热议问题