html lists - Add a different ID to each li element by jQuery -


I'm new here and I want to ask a question about jQuery.

I have such a list not listed without:

  & lt; Ul id = "pages" & gt; & Lt; Li class = "something" & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "something" & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "something" & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;  

And I want to get this & lt; Ul & gt; (i.e., wanting to add a different ID to each li displayed in & lt; li class = "". "ID =" li1 "& gt; ... ). Is there any way to get through jQuery?

Thanks a lot, Jacob

"post-text" itemprop = "text">

As jQuery 1.4, you can do this:

  $ ('# page li'). Attr ('id', function (i) {return 'page' + (i + 1); In the earlier versions you will need to write:  
  $ ('# page li'). Each (function (i) {$ ( This) .attr ('id', 'w Page '+ (i + 1));});  

... which also works in 1.4.It's a matter of priority, I think.

< / Div>

Comments