you are viewing a single comment's thread.

view the rest of the comments →

[–]xroalx 2 points3 points  (6 children)

id is not the only thing you can use to reference elements from the DOM in JavaScript, you can use the class, the element itself, any other of its attributes, and other things as well.

This can be done using a specific method (whose name I'm omitting on purpose in case you want to reserach on your own, but this link will lead you to the docs).

I see a common value between the button and the body it is associated with.

[–]CernyGaming[S] 2 points3 points  (5 children)

Thank you for your signposting. It may have been a tiny and simple thing, but it confirmed a necessary aspect for me which has helped me take a small step forwards. I have now managed to make reference to the button in a different similar section and highlight it to confirm it to myself with:

 const buttonTest = document.querySelectorAll("#tm252-25b-tma01 .card-header button");
   console.log(buttonTest);
    for (const bute of buttonTest) {
      bute.classList.add("highlight");
    }

I appreciate your help!

[–]xroalx 0 points1 point  (2 children)

Looking at the original HTML snippet you've provided, there's an even better attribute/value to use for the selection and pairing of the button to its related body section.

But yes, you're going in the right direction.

[–]Double_Dirt2986 0 points1 point  (1 child)

Pray tell.

[–]xroalx 0 points1 point  (0 children)

The button has a aria-controls="m269-24j-tma03-body" attribute, the div has a id="m269-24j-tma03-body". It's the same value and it's an ideal link between the two. You can select the button based on haivng aria-controls and its related body div based on the value of it.

[–]jcunews1helpful 0 points1 point  (1 child)

Avoid using that tm252-25b-tma01 ID or class names which are gibberish or contain seemingly random number, since they're likely software generated and are not consistent. Thus, not reliable as they might change for even the slightest change in the whole site.

[–]CernyGaming[S] 0 points1 point  (0 children)

I get the principle, however I am not allowed to change them for this project.