Welcome to the Treehouse Community
Looking to learn something new?
Tushar SinghCourses Plus Student 8,692 Points
I am currently on the jquery Basics course, the problem is :
I can easily solve all the code challenges and stuff but I have a feeling that even though I am completing those challenges, I am missing the logic behind the code.
And probably because mostly code challenges are plain stupid, anyone can solve them.
To get the better understanding of jquery, what should I do??
And when we write 'this', what does it mean?? I cant understand the keyword 'this ' refers to what exactly ?
And attr(), it is used to add a certain attribute , it may be a class, id or anything.. right??
Kevin Korte28,135 Points
The best way I feel to understand anything it so just keep using it, and avoiding copy and pasting code that "works" but you don't understand how. Sometimes when I get stuck, and I find code that works, I will copy it, but than spend the time to go back through and figure out why it works using the documentation.
I find it helpful to write my own step by step in the comments of the code. One it makes sure I understand how its working, two when I come back to that code 3 months later, I can more easily remember what the code does, and how since the comments are my own.
this referes to whatever the code that is running is currently bound to. Whatever object we are working on, this is going to refer it it. An example might be say you have a photo gallery, and when a user clicks a photo, it flips over and on the back is some information. In your code, you could use
this, and it would refer to the the particular image that was clicked.
Yes, attr is flexible enough to set, check, or manipulate attributes on an element. You can do all kinds of things, and add logic to how an attribute is set, or check if one is set. Many times, there are more then one way make something work, and sometimes there is a better way. In the event of setting a class, jquery also has a.