freeCodeCamp Challenge Guide: Target the Children of an Element Using jQuery

Target the Children of an Element Using jQuery


Solution 1 (Click to Show/Hide)
  $(document).ready(function() {
    $("#target1").css("color", "red");
    $("#target1").prop("disabled", true);
    $("#target1").parent().css("background-color", "red");
    $("#right-well").children().css("color", "orange");

<!-- 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">
      <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 class="col-xs-6">
      <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>
1 Like

Hi all.

Just noticed some weirdness on that page. When it first displays, the mobile phone display shows 2 target5’s in the left well. There should only be one. What’s interesting is if you comment out the line that clones target5, it removes both. Then, if you uncomment that line, you get just the one target5 in the left well, which is what it should be at the start.

So, it seems like there is some small bug in the code that renders that mobile phone device at the beginning. It’s almost like it runs off different HTML than our editor when it first loads, and then the editor takes over once we make changes. I don’t know. Just guessing on that. Btw, I’ve tried it in both Chrome and Firefox.

I know it sounds like a small thing, but that could easily confuse someone who is very new to this.


Why is it showing two #target5 elements

Hi. I seem to be a little stuck with this.
I have followed the guidelines and have, what I think, is the correct code for this exercise. However, I am getting the dreaded ‘red cross’.

To me it should be: $("#right-well").children().css(“color”, “orange”);

Can someone point me in the right direction?

1 Like

reset u code and do it again !

Hi Aditya, see the line number 8 of your code.
The “.clone().appendTo(”#left-well")" code has created a clone of your target 5 element on the left wall.
If you remove this line, there will be no clone of the target 5 element.
Try this.