jQuery Question in general: Divs,classes and ids


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/web-beginner-en-v6phg/1/1?curriculum_id=50a3fad8c7a770b5fd0007a1#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
While I figured out how to complete this extersize,I’m still rather confused on how to call everything in my script.js document.

```
I'm highlighted!
//as you can see highlighted is a class//

(document).ready(function() { ("#text").click(function() {
$(this).addClass(“highlighted”);
});
});
//why do I not need a # or . before calling it here?//

When you reply, may you please also include when to use #   .  or nothing for calling things
Cheers,
<do not remove the three backticks above>

#2

<div id="title" class="highlighted">I'm highlighted!</div>

to select a class we use .

.highlighted

to select an id we use #

#title

As you already say that you are adding a class

.addClass

you don’t need a .


#3

As you already know, you have to use (".class") or ("#id") when selecting an element using jquery

The (this) keyword is used when referring to the exact same $(“object”) that is called inside the function. So, for example:

the bold items refer to the same object. So you will first have to use the # or . to select your element, and if you refer to that same element within a function of then or method on that object, then you refer to that object by using the this keyword.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.