I have an unordered list with ids like so:
<li id="e1">01</li>
<li id="e2">02</li>
<li id="e3">03</li>
<li id="e4" class="event_day">04</li>
<li id="e5" class="event_day">05</li>
And a div with content like so:
<div id="descriptions">
<div></div>
<div></div>
</div>
I want to copy the ids of the list items with the class event_day and assign them to the divs with a letter at the end so that they would become:
<div id="e4d"></div>
<div id="e5d"></div>
I have come up with:
$("#descriptions>div").each(function() {
$(this).attr("id", $(".event_day").attr("id") + "d");
});
But as you can probably tell, it does not loop and rather takes the first id and assigns it to all the divs resulting in:
<div id="e4d"></div>
<div id="e4d"></div>
I'd highly appreciate it if you could explain the flaw in the logic and maybe even a link to something that I could read to improve my skills. I was looking at http://docs.jquery.com/Attributes/attr#keyfn but it did not make sense. Thanks for reading!