开发者

Perform .each function after first table row

I have the following code

 $("#description tr").each(function(){
            var description;
            var chargecode;
            var amount=0;

.......the code continues but what I am interested in is to do the each function after the 开发者_如何学JAVAfirst row. My first table row has the titles so my code keeps getting null variable values and so on. Is this possible or should I just separate the title row as a different table? All help appreciated


The parameter to the each() callback is the index. You could use that or you could define you table properly with <thead> and <tbody> and then use $("#description tbody tr")


You can use:

$("#description tr:not(:first-child)")

Working example: http://jsfiddle.net/KntKA/

Another option is $("tr:nth-child(n+2)"), but it doesn't read quite as nicely.


You can either add a class to the first row (or to all the others) and filter on that (look at the not-selector or you can use the index of the loop (which is the first parameter) which increments on every iteration and than you simple skip the first one (or you add your own counter). Of course, a better solution is:

$("#description tr:not(:first-child)") 

Which uses both the not-selector as the first-child selector. You can also use the greater than selector:

$("#description tr:gt(0)")

So many options....I would go for the last one.


Try -

 $("#description tr:gt(0)").each(function(){
            var description;
            var chargecode;
            var amount=0;

The tr:gt(0) should only get rows with in index higher than zero, therefore ignoring the first row.

Demo http://jsfiddle.net/ipr101/rPMUh/


Use $("#description tr:gt(0)").each. The :gt(0) stands for "whose index is greater then 0" and it will filter the matched elements by their index in occurring on the page. See the docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜