Answer the question
In order to leave comments, you need to log in
How to compare url and highlight link in js?
The task is such that when a user enters a page from one of the sites, there should be a check, and if the url of the site finds a link in the list of cities and with the desired href, then style is added. Where is the mistake? I so understand that I cannot take .href through querySelectorAll.
const someHrefLink = document.querySelectorAll(".some-href-link").href;
if(document.location.href === someHrefLink.forEach(el => el.style.backgroundColor = 'red');
Answer the question
In order to leave comments, you need to log in
I so understand that I cannot take .href through querySelectorAll.
[...document.querySelectorAll(".some-href-link")].map(a => a.href) // Массив всех href
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question