3.5 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.5 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName | 
|---|---|---|---|---|
| bad87fee1348bd9aed508826 | jQuery を使用して要素を複製する | 6 | 16780 | clone-an-element-using-jquery | 
--description--
要素を移動するだけでなく、ある場所から別の場所に要素をコピーすることもできます。
jQuery には clone() という関数があり、要素のコピーを作成することができます。
たとえば、left-well から right-well に target2 をコピーするには、次のようにします。
$("#target2").clone().appendTo("#right-well");
2 つの jQuery 関数をつなげていることに気づきましたか? これは関数チェーンと呼ばれ、jQuery で作業をするうえで便利な方法です。
target5 要素を複製して left-well の末尾に追加してください。
--hints--
target5 要素を right-well の中に入れます。
assert($('#right-well').children('#target5').length > 0);
target5 要素のコピーも left-well の中に入れます。
assert($('#left-well').children('#target5').length > 0);
jQuery のみを使用してこれらの要素を移動してください。
assert(!code.match(/class.*animated/g));
--seed--
--seed-contents--
<script>
  $(document).ready(function() {
    $("#target1").css("color", "red");
    $("#target1").prop("disabled", true);
    $("#target4").remove();
    $("#target2").appendTo("#right-well");
  });
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
  <h3 class="text-primary text-center">jQuery Playground</h3>
  <div class="row">
    <div class="col-xs-6">
      <h4>#left-well</h4>
      <div class="well" id="left-well">
        <button class="btn btn-default target" id="target1">#target1</button>
        <button class="btn btn-default target" id="target2">#target2</button>
        <button class="btn btn-default target" id="target3">#target3</button>
      </div>
    </div>
    <div class="col-xs-6">
      <h4>#right-well</h4>
      <div class="well" id="right-well">
        <button class="btn btn-default target" id="target4">#target4</button>
        <button class="btn btn-default target" id="target5">#target5</button>
        <button class="btn btn-default target" id="target6">#target6</button>
      </div>
    </div>
  </div>
</div>
--solutions--
<script>
  $(document).ready(function() {
    $("#target1").css("color", "red");
    $("#target1").prop("disabled", true);
    $("#target4").remove();
    $("#target2").appendTo("#right-well");
    $("#target5").clone().appendTo("#left-well");
  });
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
  <h3 class="text-primary text-center">jQuery Playground</h3>
  <div class="row">
    <div class="col-xs-6">
      <h4>#left-well</h4>
      <div class="well" id="left-well">
        <button class="btn btn-default target" id="target1">#target1</button>
        <button class="btn btn-default target" id="target2">#target2</button>
        <button class="btn btn-default target" id="target3">#target3</button>
      </div>
    </div>
    <div class="col-xs-6">
      <h4>#right-well</h4>
      <div class="well" id="right-well">
        <button class="btn btn-default target" id="target4">#target4</button>
        <button class="btn btn-default target" id="target5">#target5</button>
        <button class="btn btn-default target" id="target6">#target6</button>
      </div>
    </div>
  </div>
</div>