jQuery: How to count table columns?

前端 未结 15 1469
天命终不由人
天命终不由人 2020-12-28 13:20

Using jQuery, how would you figure out how many columns are in a table?



15条回答
  •  天涯浪人
    2020-12-28 13:29

    var foo = document.getElementById("price-test-table")
    foo.tBodies["0"].firstElementChild.children.length
    
    1. Give your table an id name
    2. Assume your rows all have the same amount of columns and you have a table body
    3. Use above code, which I think is the simplest on here, similar to first answer but provides a little more detail

提交回复
热议问题