How to compare the page URL and links, and with a match to delete?
Closed due to the fact that the essence of the issue is incomprehensible to the participants by aleksandr barakin , 0xdb , Vladimir Klykov , andreymal , Enikeyschik January 17 at 10:29 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Who to delete something? The accepted answer is good, but the wording of the question is completely indistinct - andreymal
|
2 answers
You can use this option:
let url = location.href; url = 'yandex.ru' // Удалить эту строчка, сделанно для имитации ссылки. $('.url').each(function(){//Переберём дивы let thisURL = $(this).data('url'); // Получим атрибут data-url if(thisURL==url) $(this).addClass('remove'); // если адресс страницы совпадает с data-url - вешаем класс remove. Это для визуализации. // Чтобы удалить блок, используйте ↓ // $(this).remove(); }); .remove {opacity: .5; color: red;} <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="url" data-url="google.com">google.com</div> <div class="url" data-url="yandex.ru">yandex.ru</div> |
This is how you can get the URL of the current page.
var page=window.location.href; A link on the id of the element can be obtained
Then compare and do what you want
|