Adding an ID to each li in a ul
Hi Guys,
I don´t understand my failure in this code.
$().ready(function () {
var n = $(".mainmenu li").length;
$(".mainmenu li").each(function(n, element){$(element).attr("id", "link" + n);});
when the document is ready and javascript is enabled. I will count all li elements in the mainmenu ul.
then I will add the id attrribute to each li so that my code looks like:
before:
<ul class="maimenu">
<li></li>
<li></li>
...
after:
<ul class="maimenu">
<li id="link1"></li>
<li id="link2"></li>
...
Can someone give me a tip?