How can I select a specific column in a row using jQuery and JavaScript?

前端 未结 3 1995
悲&欢浪女
悲&欢浪女 2021-01-11 16:03

I am very new to jQuery and JavaScript. I have a small question. Let\'s say i have a HTML table like the following

相关标签:
3条回答
  • 2021-01-11 16:16

    something like

    $('#mytable tr:eq(0) td:eq(1)').text('ChangedText');
    

    will select the first row, second column (0 based) of the given element (TABLE). In your case, since you know the row id :

    $('#mytable #element td:eq(1)').text('ChangedText');
    

    or simply

    $('#element td:eq(1)').text('ChangedText');
    
    0 讨论(0)
  • 2021-01-11 16:26
    $("#element td:nth-child(2)").text('ChangedText');
    

    Here's an example.

    0 讨论(0)
  • 2021-01-11 16:32

    Gert's code is how I would have implemented what you are asking so I won't repost it. However since you are new to jquery/javascript, you might like this tool I use to make sure my selectors are working http://www.woods.iki.fi/interactive-jquery-tester.html.

    Cheers, Joe

    0 讨论(0)
提交回复
热议问题