Simple JS action?

Hello, please tell me is it possible to make js or jquery, same thing.
If the address page displays the name of the links that we have this link assigned to the class ?
In other words, if the site address is the address of the page to index1 or index2, then the link which contains this page we assign the class ?
<a href="https://site-name/index1">Name 1</a>
<a href="https://site-name/index2">Name 2</a>
<a href="https://site-name/index3">Name 3</a>
April 7th 20 at 15:41
5 answers
April 7th 20 at 15:43
document.querySelectorAll('a').forEach(link => {
 if (link.pathname === window.location.pathname) {
 } else {
April 7th 20 at 15:45
the <script>

if(window.location.pathname == '/index.php/pages') {
April 7th 20 at 15:47
Easy! Use the class to work with URLS.
To current address:
let url = new URL(document.location.href)
do the analysis of the url, I advise you to look at

there you will find parse your URL and will be able to pull the required option or link for analysis.

Then form a link with class depending on the conditions.
April 7th 20 at 15:49
`window.location.pathname` - then your reference settings
like this.
April 7th 20 at 15:51
Get the href attribute, trim/regex/count the number of characters from the end/beginning. To check condition. Add class.

Find more questions by tags JavaScriptjQuery