0

I'm doing the freeCodeCamp Simon Game challenge (JSfiddle). I can't work out why my .click() isn't working at all. I've used this for all of my other projects without issue.

The HTML is here:

    <span class="title-label">designed and coded by <a href="http://www.daveingles.com" id="linkedIn" target="_blank">Dave Cook</a></span>
      </div>
<div class="main">

  <div class="button-holder">


    <div class="quarter red">
      <div id="red"></div>
    </div>
    <!--quarter red-->
    <div class="quarter yellow">
      <div id="yellow"></div>
    </div>
    <!--quarter red-->
    <div class="quarter green">
      <div id="green"></div>
    </div>
    <!--quarter red-->
    <div class="quarter blue">
      <div id="blue"></div>
    </div>
    <!--quarter red-->
    <div class="center">
      <h1 id="simon">Simon</h1>
      <div class="center-row">
        <div class="center-cell">
          <div class="screen">--</div>
        </div><!--cell-->
        <div class="center-cell">
          <div class="btn r"></div>
          </div><!--cell-->
        <div class="center-cell">
          <div id="strict-light"></div>
        <div class="btn y"></div>
          </div><!--cell-->
        <div class="center-cell">
            <span>COUNT</span>
          </div><!--cell-->
        <div class="center-cell">
       <span> START</span>
          </div><!--cell-->
        <div class="center-cell">
        <span>STRICT</span>
          </div><!--cell-->

      </div><!--center-row-->
      <div class="bottom-row">
        <div class="center-cell">
          <span>OFF</span>
        </div>
        <div class="center-cell">
          <div class="off-on">
            <div id="switch"></div>
          </div>
        </div>
        <div class="center-cell">
          <span>ON</span>
        </div>
      </div><!--bottom-row-->

    </div>
    <!--center-->
  </div>
  <!--button-holder-->
</div>
<!--main-->

This is the JavaScript:

$("*").click(function(){
  console.log($(this));
  activateSection("red");
});

$("#yellow").click(function(){
  console.log($(this));
  activateSection("yellow");
});

The first click function works fine so I can be sure that JQuery is installed and the syntax is correct. Whenever I try to put a specific class or id in the element selector, nothing happens.

4
  • 1
    Could this have something to do with using z-index on the elements? Commented Aug 18, 2017 at 1:52
  • The div with id yellow does not have any dimensions Commented Aug 18, 2017 at 1:54
  • Well spotted! I've updated this now setting height and width to 100% each but it's not made any difference. Commented Aug 18, 2017 at 2:05
  • When right-clicking and pressing 'inspect element', the element doesn't show automatically, I can only see <body> and <html> sections initially. I assume this is caused by the same issue. Commented Aug 18, 2017 at 2:08

3 Answers 3

1

It turns out that it was having the z-index of the clickable elements as < 0, meaning that they were effectively covered by the <body> and <html> elements.

I've since made the z-indexes positive and this is working.

Sign up to request clarification or add additional context in comments.

Comments

0

I think the problem lays with how you style your circle. I inspect your jsfiddle and figure out that your #red's size is 200ish x 0, which basically means it doesn't even have a body for you to click and interact. In the mean time, your .quarter.red have a size, so maybe trying to click on it?

Solution:

$(".quarter.red").click(function(event) {});

Comments

0

There is a lot going on here with your z-index . It's causing all you issues. I've made changes to your .quarter .center .main .button-holder to get that right. I also changed your click selector for the red or yellow class.

You should never go negative with z-index it's is very rare to have a good reason to do that, in my experience.

here is the updated version: https://jsfiddle.net/44xh92ny/3/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.