Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

My jQuery Project

Hi, after start watching jQuery basics course. I built my small project. I welcome anyone to take a look on it and give me feedback (may be even why and how my codes will work?)

1 Answer

Hey Zayn,

First of all, great use of jQuery basics. Unlike many other students, you took a step into actually putting your knowledge to work by creating this snippet of code.

One way you can optimize your JS code is to remove the function entirely and change your click function to something like this.

$("#circle").click(function() {
    $(this).next().html("I KNOW YOU HAVE CLICKED IT!");
});

I hope this helps.

Thanks!

This code works

function iKnowYouHaveClickedIt() {
          return $("#circle").next().html("I KNOW YOU HAVE CLICKED IT!");
      }

      $("#circle").click(function iKnowYouHaveClickedItttttt() {
          iKnowYouHaveClickedIt();
      });

But why this code does not?

function iKnowYouHaveClickedIt() {
          return $("#circle").next().html("I KNOW YOU HAVE CLICKED IT!");
      }

      $("#circle").click(iKnowYouHaveClickedIt();

Could you help me out?