Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

<Table id="mytable">
 <tr id="element">
  <td>value</td>
  <td>text</td>
</tr>
</Table>

In the above example i know the row id and i want to change the value of the second column of the row with that particular id.

I need a result something like the following:

 <Table id="mytable">
 <tr id="element">
  <td>value</td>
  <td>ChangedText</td>
</tr>
</Table>

So my question is: how can I select the 2nd column of the first row with a given id in order to change the value?

like image 753
swati Avatar asked Sep 01 '10 22:09

swati


People also ask

How do I select a specific column in jQuery?

Columns can be selected using column(). select() or columns(). select() API methods. You can enable single or multiple items selection using select.

How do I select something in jQuery?

The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field. Syntax: $(selector). select(function);

How do you select a column in HTML?

In Mozilla Firefox, users may highlight only certain rows, columns, or cells of an HTML table by holding down the Ctrl on the keyboard and click each cell individually.


1 Answers

$("#element td:nth-child(2)").text('ChangedText');

Here's an example.

like image 99
Gert Grenander Avatar answered Oct 18 '22 21:10

Gert Grenander