My Code Looks Right, But It Does Not Work


#1


https://www.codecademy.com/courses/web-beginner-en-v6phg/1/1?curriculum_id=50a3fad8c7a770b5fd0007a1#


My code seems to be correct, but the browser doesn't translate it, so I cannot move on.


Replace this line with your code. 
$(document).ready(function() {
    $('#text').click(function() {
        $(this).addClass('.highlighted');
    });
});


#2

so now your class of text element is .highlighted, so if you know want to select this in css you get ..highlighted


#3

I still do not understand.


#4

you add a class .highlighted to your element, you should add a class of highlighted to your element


#5

The syntax example that is provided is not clear in explaining that the "." is unnecessary following the .addClass function. See below. In the example the proper syntax for the selector is $('#text') the ID indicator is included, whereas the Class indicator "." is omitted.

$('selector').addClass('className');
$('selector').removeClass('className');

This is the type of inconsistency really needs to be spelled out for newer programmers.


#6

but in the example you can see the full stop being omitted:

The syntax looks like this:

$('selector').addClass('className');
$('selector').removeClass('className');

And nothing is stopping learners from checking the official jquery docs

but it makes sense, in the selector we need to specify if we are dealing with element, class or id. addClass will add a class, so adding the full stop is not need


#7

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