Confusing assignment introduction


#1

Hi guys,

As I was doing this exercise I felt like the instructions confused me and I thought I would mention it to the creators of codecademy.

You write

Remember: You aren't selecting anything, you are modifying your element. This means that you do not need # or . before your class.

Yet as you can see in my solution below, it was needed to complete the challenge. I had the right solution early on but redacted # and . infront of classes and id's as per instructions.

Maybe I misinterpreted the challenge and/or instructions, but it had me busy for 20 minutes until I just ignored the instructions and went with a solution I found online.

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

$(document).ready(function() {
    $('#text').click(function() {
    $(this).addClass('highlighted');
   
   });
   
});

All in all, thanks for a great tool to increase my skills in jQuery. Have a great weekend!


#2

From instruction:

The syntax looks like this:

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

where 'selector' is the HTML element you want and 'className' is the class name you want to add or remove.

Remember: You aren't selecting anything, you are modifying your element. This means that you do not need # or . before your class.

Read once more about selector:
'selector' is the HTML element you want and 'className' is the class name you want to add or remove.

This means:

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

$('#text').click(function() {
   $(this).addClass('.highlighted'); // className '.highlighted' is wrong
});

$('#text').click(function() {
   $(this).addClass('highlighted'); // className 'highlighted' is correct and you aren't selecting anything, you are modifying your element you clicked
});

#3

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