April 4, 2012
jQuery each number
Question by Ivan C.
I have a idea to make table like this
1. something1
2. something2
3. something3
I have made a table:
<table>
<tr><td id="rb">...
<tr><td id="rb">...
</table>
so in #rb is this sequence number starting from 1.
I have this jQuery code but it doesn’t work. Can you pls help 🙂
$('tr').each(function(index)
{
$('#rb').append(index);
});
It just make
012345
in the first #rb
Thanks in advance!
Answer by Starx
You should not give same id to more than one element within same HTML document. You can do the same using class="rb"
instead.
$('tr').each(function(index) {
$(this).find('.rb').append(index);
});