Get second child using jQuery

前端 未结 9 1541
灰色年华
灰色年华 2020-12-12 15:03
$(t).html()

returns

test1test2

I want to retrieve the second td<

9条回答
  •  一向
    一向 (楼主)
    2020-12-12 15:50

    How's this:

    $(t).first().next()
    

    MAJOR UPDATE:

    Apart from how beautiful the answer looks, you must also give a thought to the performance of the code. Therefore, it is also relavant to know what exactly is in the $(t) variable. Is it an array of or is it a node with several s inside it? To further illustrate the point, see the jsPerf scores on a

      list with 50
    • children:

      http://jsperf.com/second-child-selector

      The $(t).first().next() method is the fastest here, by far.

      But, on the other hand, if you take the node and find the children and and run the same test, the results won't be the same.

      Hope it helps. :)

提交回复
热议问题