【问题标题】:How can i continuesly using appenTo() when i click a button?单击按钮时如何连续使用 appenTo()?
【发布时间】:2022-12-02 20:09:30
【问题描述】:

im trying to reverse div with Jquery which when i click a button the divs will reverse and switch place

<div class=\"player1\">
  <div class=\"player1-a\">
      <div class=\"pemain p1a\">
           <h4>Samsudin</h4>
      </div>
    
       <div class=\"cock 1a\">
    
       </div>
   </div>
    
   <div class=\"player1-b\">
      <div class=\"pemain p1b\">
          <h4>Joko</h4>
      </div>
    
      <div class=\"cock 1b\">
    
      </div>
   </div>

</div>
<button class=\"btn btn-light score_plus\" id=\"score_kiri\"><h1>SCORE</h1></button>

whenever this button clicked the div p1b will move to div player1-a and so do div p1a will move to div player1-b.

Here\'s my jquery code that the divs only move once and dont move again when i click again.

$(\'#score_kiri\').click(function() {
        $(\'#player_kiri\').val(i++);
        $(\'.p1a\').appendTo(\'.player1-b\');
        $(\'.1a\').appendTo(\'.player1-b\');
        $(\'.p1b\').appendTo(\'.player1-a\');
        $(\'.1b\').appendTo(\'.player1-a\');
        
        $(\'.p1a\').append(\'.player1-b\');
        $(\'.1a\').append(\'.player1-b\');
        $(\'.p1b\').append(\'.player1-a\');
        $(\'.1b\').append(\'.player1-a\');
    });

    标签: javascript jquery


    【解决方案1】:
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 2020-09-09
    相关资源
    最近更新 更多