I have a list of div’s in my code which have a custom data-attribute assigned to them which is “data-for”.
What I need to do is find the div which has a data-for attribute that matches part of the URL.
For example, the list of div’s may be:
<div data-for="north-west"></div>
<div data-for="south-west"></div>
etc
If the URL of the current page is http://www.mysite.com/shops/north-west.html, I want to find the div with the north-west data-attribute (div data-for=”north-west)and assign an ID or class to it.
Can anyone help me out with this one? It needs to be speedy as the list of divs is quite long.
Thanks for help in advance.
1 Answer