jQuery question

Hello,

I have a question on a lesson 117 “Target the Parent of an Element Using jQuery”.
The instruction was to “Give the parent of the #target1 element a background-color of red.”
$("#target1").parent().css("background-color", "red");

I’m trying to understand better about the syntax above. The parent of #left-well is
<div class="container-fluid">
In the instruction is also says the parent element of <div class="container-fluid">,
which itself has the parent body"

Also I do not user stand "The .parent() method should be called on the #target1 element."
I do not see where the #target1 is consider to be the body of #left-well.
not sure how it goes from #left-well to body in the syntax above.

<script>
  $(document).ready(function() {
    $("#target1").css("color", "red");
    $("#target1").prop("disabled", true);
    $("#target4").remove();
    $("#target2").appendTo("#right-well");
    $("#target5").clone().appendTo("#left-well");
    $("#target1").parent().css("background-color", "red")
  });
</script>

<!-- Only change code above this line. -->

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

We’re not really worried about body here. $("#left-well").parent() is <div class="container-fluid">. The challenge text is simply pointing out that <div class="container-fluid"> has a parent, too, even though we’re not going to access it here.

1 Like