# Help with my calculator

**URL:** <https://forum.freecodecamp.org/t/help-with-my-calculator/138980>\
**Category:** General\
**Created:** [July 29, 2017, 9:44pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980 "2017-07-29T21:44:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicknyr](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@Nicknyr](https://forum.freecodecamp.org/u/Nicknyr)\
**Post date:** [July 29, 2017, 9:44pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/1 "2017-07-29T21:44:00Z")

</div>

I have my calculator project finished for the most part. Here’s what I have so far:

> **[JyGWrB](https://codepen.io/nick_kinlen/pen/JyGWrB)**
>
> ...

One of the issues I’m having is with the buttons. For the buttons to work you have to click precisely on the number/symbol, clicking the outer parts of the button won’t work. I think this is because in my javascript file I am targeting the span tag via

var elem = document.querySelectorAll(".button2");

I would like to target the entire button by targeting the div element the span is inside, but I can’t target the div with the querySelectorAll() function i.e. passing “button” (which is the div’s class) doesn’t work:

var elem = document.querySelectorAll(".button");

How do I target a div with querySelectorAll? Or do I need to use a different function for that?

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [July 29, 2017, 11:28pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/3 "2017-07-29T23:28:24Z")

</div>

> [@Nicknyr](#):
>
> I would like to target the entire button by targeting the div element the span is inside, but I can’t target the div with the querySelectorAll() function i.e. passing “button” (which is the div’s class) doesn’t work:  
> var elem = document.querySelectorAll(“.button”);

I’m not sure what you mean by that. It works fine for me. Like Dawson says, just make that change.

---

<div class="post-metadata">

**Author:** ![wadie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/wadie/32/94485_2.png) [@wadie](https://forum.freecodecamp.org/u/wadie)\
**Post date:** [July 29, 2017, 11:47pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/4 "2017-07-29T23:47:26Z")

</div>

I would suggest to have a `button` tag for each number instead of `div`, and then you can target `button.number1` for example

---

<div class="post-metadata">

**Author:** ![Nicknyr](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@Nicknyr](https://forum.freecodecamp.org/u/Nicknyr)\
**Post date:** [July 30, 2017, 5:31pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/6 "2017-07-30T17:31:49Z")

</div>

What I mean is if I try to target “.button” with querySelectorAll it doesn’t work.

I think this is because the span tag within the div is a child element and I’m not targeting it. Do I need to target it with the .childNodes[] function?

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [July 30, 2017, 9:54pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/7 "2017-07-30T21:54:55Z")

</div>

Sorry, for JQuery I think it would be this:

```auto
  var elem = $(".button");

```

Though, it JQuery I often see it labeled like:

```auto
  var $elem = $(".button");

```

so you remember that _$elem_ is a JQuery selector. It’s optional, but if you do it you’d have to change other references to that variable too.

Does that not work for you? It works for me when I plug it into your code. (After I add JQuery in the _settings/Javascript/quick-add_)

---

<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 17, 2021, 8:47pm UTC](https://forum.freecodecamp.org/t/help-with-my-calculator/138980/9 "2021-01-17T20:47:04Z")

</div>

Closed on January 17, 2021, 8:47pm UTC


