How do i change css style based on js get request status? [closed]

Solution for How do i change css style based on js get request status? [closed]
is Given Below:

On my website, I have several links as my table of content

<li><a href="something-ch-1.html">Ch. 1 - TitleHere</a></li>
<li><a href="something-ch-2.html">Ch. 2 - TitleHere</a></li>
<li><a href="something-ch-3.html">Ch. 3 - TitleHere</a></li>

I want to send get request (using js) to those anchor texts for checking whether the link inside 404 not found or 200 ok. and if it is 404 not found, I want its style to change. Let just assume its style to change in color.

how do I do this?

You can achieve that by using JS fetch. But first you have to use selector to get value of the href attribute. Then forEach of them, you may want to create a fetch request and get a response. With returned response.status attribute, you can continue to next step. More information about fetch can be found here

You can check the given link using ajax in window.onload. Check the corresponding request and configure style according to it.