jQuery Question in general: Divs,classes and ids



While I figured out how to complete this extersize,I'm still rather confused on how to call everything in my script.js document.

 <div id="title" class="highlighted">I'm highlighted!</div>
//as you can see highlighted is a class//

$(document).ready(function() {
    $("#text").click(function() {
//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


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

to select a class we use .


to select an id we use #


As you already say that you are adding a class


you don't need a .


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.


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