Clone an Element Using jQuery (which creates duplicated buttons)

Clone an Element Using jQuery (which creates duplicated buttons)
0

#1

Tell us what’s happening:

The clone().appendTo() somehow appends 2 copy buttons in the left well. The code passes the challenges, but I don’t think it’s right. Am I the only one who sees this?

Your code so far

<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>

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8.

Link to the challenge:


#2

The code is correct, but the output is indeed wrong. Have you tried refreshing or using another browser?


#3

I was using Safari (and refreshed several times). Also just had a try on Chromium on Xubuntu, without even login. Loading just a later challenge that has this code preloaded shows the same dual target5’s.

The dup buttons show on my Firefox/Xubuntu, and Safari/iOS as well.

Tried the .clone().appendTo() code using the page console on another web site which also has jquery, and the result is correct – only one button is cloned.

Do you guys not see the same? (i’m feeling a bit creepy now :slight_smile:


#4

Apparently it’s a bug, see https://github.com/FreeCodeCamp/FreeCodeCamp/issues/5072

I was getting either multiple button or no buttons across multiple browsers with or without privacy modes. I finally just copied the text from the post in that thread by user patsul12 and was able to complete the step.


#5

this is what i get http://nimb.ws/BJtqmM