javascript - Get second last child td in html table - Stack Overflow

I am able to get td's last child using this$jq('#stripeTable > tbody > tr:nth-child(�

I am able to get td's last child using this

$jq('#stripeTable > tbody > tr:nth-child('+(i+1)+') >td:last-child').text(colValues +" < "+ colValuesWithOverTime);

what to do and get second last child of td like i am getting last child using td:last-child

I am able to get td's last child using this

$jq('#stripeTable > tbody > tr:nth-child('+(i+1)+') >td:last-child').text(colValues +" < "+ colValuesWithOverTime);

what to do and get second last child of td like i am getting last child using td:last-child

Share Improve this question edited May 6, 2017 at 7:54 LF-DevJourney 28.6k30 gold badges165 silver badges316 bronze badges asked May 6, 2017 at 7:17 Muhammad Faizan KhanMuhammad Faizan Khan 10.6k21 gold badges105 silver badges197 bronze badges 3
  • nth-last-child – Mr Lister Commented May 6, 2017 at 7:25
  • stackoverflow./questions/22605785/… – LF-DevJourney Commented May 6, 2017 at 7:39
  • 1 Possible duplicate of Select second to last element – Imanuel Commented May 6, 2017 at 7:49
Add a ment  | 

3 Answers 3

Reset to default 5

Try td:nth-last-child(2). This will select the 2nd child from the end.

console.log($("td").last().prev().text());
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>

use last and prev,

$("td").last().prev();

Use .eq() function to get second last from jQuery array

var count = $('td').length;
var secondLast = $('td').eq(count - 2);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745357057a4624183.html

相关推荐

  • javascript - Get second last child td in html table - Stack Overflow

    I am able to get td's last child using this$jq('#stripeTable > tbody > tr:nth-child(�

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信