I have a list of links and a list of markers which are generated dynamically:
The structure looks like this:
<div>
<a id="link{{i}}>Link {{i}}</a>
</div>
<div>
<div id="marker{{j}}">Marker {{j}}</div>
</div>
When the content is dynamically generated – it will end up looking like this:
<div>
<a id="link1">Link 1</a>
<a id="link2">Link 2</a>
<a id="link3">Link 3</a>
</div>
<div>
<div id="marker1">Marker 1</div>
<div id="marker2">Marker 2</div>
<div id="marker3">Marker 3</div>
</div>
Is there a way to write a function in jQuery which would ensure that when the user hovers on link 1 – the background-color of marker 1 changes to yellow, and on link 2 – the background-color of marker 2 changes to yellow and so on…
2
Answers
I’ve created a basic example, I’ve added a generic
marker
class to style the markers.Example:
If you can’t change your html, you can use the attribute starts with selector and
eq
to add a class to the corresponding marker: