JQuery going through a set of UL and dynamically set ids incremently on each one

Posted by Calibre2010 on Stack Overflow See other posts from Stack Overflow or by Calibre2010
Published on 2010-05-18T13:16:30Z Indexed on 2010/05/18 13:20 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

I have an unordered list which contains serveral items called 'oListItems' the UL has a class but no id.

The class OuteroListItems contains many of oListitems

 oList.AppendFormat("<ul class='OuteroListItems'>");
            oList.AppendFormat("<li>");
            oList.AppendFormat("<ul class='oListItems'>");
            oList.AppendFormat("<li>" + s.sName + "</li>");
            oList.AppendFormat("<li>" + s.eName + "</li>");
            oList.AppendFormat("<li>" + s.SDate + "</li>");
            oList.AppendFormat("<li>" + s.EDate + "</li>");
            oList.AppendFormat("</ul>");
            oList.AppendFormat("</li>");
            oList.AppendFormat("</ul>");

I want for each .oListItem class that gets retrieved, add dynamically an id to it.

 var o = $(".oListItem");

    $.each(o, function (){

      var f = $(this).attr("id", 'listItem' + i);

        i++;
    });

wasent sure on the approach, this is what I have so far?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about attributes