Introduction to jQuery: 6. Targeting By Class

https://www.codecademy.com/courses/learn-jquery-introduction/lessons/jquery-setup/exercises/targeting-by-class?action=lesson_resume&course_redirect=learn-jquery

I’m having trouble with question 1 on part 6 of Introduction to jQuery. It says:

  1. We have several thumbnail images with a class of ‘product-photo’, but they don’t appear in the site because their display property is set to none in style.css . Let’s start by using jQuery to target every ‘.product-photo’.
    I wrote in the editor $(’.product-photo’) and when I go to run it, it gives me a red x and asks if I targeted ‘.product-photo’. I don’t understand why it is doing this. Please help me with this question.

Cannot tell what the issue is. Suggest refresh the page and see what happens.

1 Like

Even after I refreshed, it still gave me the same error message. I’m using Chrome. Could it be a problem with the browser?

That will be borne out by testing. I use FF, myself.

1 Like

But my question is, did I write the correct code for the first part because I’m pretty sure for targeting the product-photo class it needs to be $(’.product-photo). Why is it giving me the error message, did you target ‘.product-photo’?

If your code was as above, there is a missing quote. But if the quote was there, then the selector is correct.

$('.product-photo')

Is your code contained in a ready wrapper?

Note that the above is an incomplete statement but the SCT should be ignoring any error that is thrown and checking the selecto composition, only. The second step completes the statement:

$('.product-photo').show();

See if you can complete the exercise that way.

1 Like

I actually typed it as ('.product-photo'). It is contained in a ready wrapper and I will attach .show() to (’.product-photo’).

It’s still giving me the error.

What is the problem with this part of Introduction to jQuery? I entered in the correct code. Even after I refreshed the browser (I’m using Chrome), it doesn’t register what I did and when I click Run, it gives me the same error.

Did you try Firefox or Edge?

1 Like

I tried Firefox, got the same issue.

Please post your entire code. Thanks.

1 Like

This is my entire code for 6. Targeting By Class question 1
(document).ready(() => { (’.product-photo’)
});

That code is valid but it may not be what the SCT is expecting. Try using the old form…

$(document).ready(function () {
  $(’.product-photo’)
});

Edit… Just checked and my code passed using the arrow function so that isn’t the problem. But try the other form, anyway.


Okay, with magnification we can see that your code is using smart quotes. Change,

’.product-photo’

to,

'.product-photo'
1 Like

Did all of that and still the same problem. Don’t know why compiler is rejecting my code.

I was hoping we could move this topic back to the track forum, but alas, here it shall remain. Wish there was more one could offer.

$(document).ready(() => {
  $('.product-photo').show();
});

is what I had after step 2.

1 Like