I have the following HTML script above that I added as a screenshot. I now have to create a command which stores the (“Raspberry Pi music machine”) in a variable called selection 2, using the querySelector(). My answer would have been:
let selection2 = document.querySelector("#projects-page .thumbnail.p2.selected h2");
but it’s apparently too specific. Does somebody know the answer?
Actually, scratch that, I misread your image. It’s always better to post actual code in here than images of code. The images can be hard to read and it doesn’t allow us to copy/paste for our own testing.
And I would follow up and ask what the goal is here. That selector seems to be perfect for extracting the text you’re looking for, but without context to your goal, we have to go off limited information.
Hello Thank you for your quick answer. I am currently taking a beginners class at university and we were given a portfolio HTML document with the code that I gave you above.
The question that was given to me now is : Using querySelector(), what command selects the element that has the title of the project description (“Raspberry Pi music machine”) and stores it into variable named selection2 ?
I am submitting my answer online which means I only get a wrong or right on my answer. When I asked the teacher why my answer was wrong he mentioned that h2 is not needed in that specific case and that .p2 is also too specific because the selector wouldn’t work anymore if it was called p1 for example. I still don’t know the answer though
I think we would need to know the exact requirements for this problem. As @marcusparsons said, the selector list you used seems to do what you want it to do. But if there are other requirements that we don’t know about that make your solution invalid then we can’t really comment on that.
Hello I only have the task that I posted under Marcus post x It’s part of an university online course so I thought I’m just doing something wrong at this point
OK, then we are all confused as to why it won’t accept your apparently correct solution
Well, you have to have something uniquely identifiable about the element in order to determine if it contains the “title of the project description”. So if your instructor is saying that the title of the project description is not always going to be in an h2 element and is not always going to be nested in a .p2 element then what one unique characteristic can be used to determine how to find the title of the project?
Until you know that I don’t see how you can write an accurate selector for this problem.
Well at least it’s comforting to know that my answer doesn’t seem to be the problem Thank you for helping out, I guess I will just have to reach out to my professor again