# Target a Specific Child of an Element Using jQuery

**URL:** <https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679>\
**Category:** General\
**Created:** [May 19, 2016, 3:06pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679 "2016-05-19T15:06:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianmoran1](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@julianmoran1](https://forum.freecodecamp.org/u/julianmoran1)\
**Post date:** [May 19, 2016, 3:06pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/1 "2016-05-19T15:06:16Z")

</div>

Im stuck at this exercise

it says this:

You’ve seen why id attributes are so convenient for targeting with jQuery selectors. But you won’t always have such neat ids to work with.Fortunately, jQuery has some other tricks for targeting the right elements.jQuery uses CSS Selectors to target elements. target:nth-child(n) css selector allows you to select all the nth elements with the target class or element type.Here’s how you would give the third element in each well the bounce class:$(".target:nth-child(3)").addClass(“animated bounce”);Make the second child in each of your well elements bounce. You must target the children of element with the target class.

and i wrote this  
$("#target:nth-child(2)").addClass(“animated bounce”);

I dont know whats wrong  
please help!

---

<div class="post-metadata">

**Author:** ![MK-61](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mk-61/32/523_2.png) [@MK-61](https://forum.freecodecamp.org/u/MK-61)\
**Post date:** [May 19, 2016, 3:10pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/2 "2016-05-19T15:10:59Z")

</div>

Hi!

Hint: think about with what you need to replace **‘#’** in: $("#target:nth-child(2)").addClass(“animated bounce”);

---

<div class="post-metadata">

**Author:** ![julianmoran1](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@julianmoran1](https://forum.freecodecamp.org/u/julianmoran1)\
**Post date:** [May 19, 2016, 3:16pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/3 "2016-05-19T15:16:23Z")

</div>

with a dot. But I dont know why Because target is an id, not a class

---

<div class="post-metadata">

**Author:** ![gwenf](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gwenf/32/95309_2.png) [@gwenf](https://forum.freecodecamp.org/u/gwenf)\
**Post date:** [May 19, 2016, 3:34pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/4 "2016-05-19T15:34:52Z")

</div>

So, it looks like you already know how to select classes, id’s, etc. in jquery.

Can you post a screen shot or all of the challenge code? It’s hard to see where the discrepancy is without seeing the whole challenge.

---

<div class="post-metadata">

**Author:** ![MK-61](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mk-61/32/523_2.png) [@MK-61](https://forum.freecodecamp.org/u/MK-61)\
**Post date:** [May 19, 2016, 3:38pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/5 "2016-05-19T15:38:57Z")

</div>

In that case, you should do that:

```
$("#target3").addClass("animated bounce");
$("#target6").addClass("animated bounce");

```

Then you accessing by ID. And completing that task (if there would no req for “nth-child”

But you need to use “nth-child(2)”, and targeting CLASS.

$(".target:nth-child(2)").addClass(“animated bounce”);

One line instead of two.

---

<div class="post-metadata">

**Author:** ![MK-61](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mk-61/32/523_2.png) [@MK-61](https://forum.freecodecamp.org/u/MK-61)\
**Post date:** [May 19, 2016, 3:56pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/6 "2016-05-19T15:56:04Z")

</div>

Ok, another way. You just “oversaturated” by “target” everywhere. Check this:

```
    <button class="btn btn-default trgt" id="target1">#target1</button>
    <button class="btn btn-default trgt" id="target2">#target2</button>
    <button class="btn btn-default trgt" id="target3">#target3</button>

```

One of two group, I simple changed class to “trgt” everywhere.

So, code like $(".trgt:nth-child(2)").addClass(“animated bounce”);  
should be a bit more clear for an eye. “Class “trgt”, child second.”

---

<div class="post-metadata">

**Author:** ![TrishanaCann](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/trishanacann/32/162793_2.png) [@TrishanaCann](https://forum.freecodecamp.org/u/TrishanaCann)\
**Post date:** [April 23, 2017, 8:23pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/8 "2017-04-23T20:23:14Z")

</div>

I’m stuck here too, it must be something I’m not seeing. I know this is an old question but is anybody still here?

 ![](https://global.discourse-cdn.com/freecodecamp/original/3X/f/9/f9250ff18be7bdb77362baa0a78926eb27679f88.png)

---

<div class="post-metadata">

**Author:** ![hpredieri](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@hpredieri](https://forum.freecodecamp.org/u/hpredieri)\
**Post date:** [May 19, 2017, 5:33pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/9 "2017-05-19T17:33:09Z")

</div>

```
$(".target:nth-child(2)").addClass("animated bounce");

```

Why does this code work? what is “.target” referring to? Shouldn’t it be “.well”?

---

<div class="post-metadata">

**Author:** ![kasirajr](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@kasirajr](https://forum.freecodecamp.org/u/kasirajr)\
**Post date:** [November 30, 2017, 11:51am UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/10 "2017-11-30T11:51:00Z")

</div>

addClass() fucntion should be written in camel case

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:10pm UTC](https://forum.freecodecamp.org/t/target-a-specific-child-of-an-element-using-jquery/1679/11 "2021-01-16T13:10:09Z")

</div>

Closed on January 16, 2021, 1:10pm UTC


