Im using Jeditable inside a table, to update a value.
JavaScript
x
20
20
1
function updateOwner(row, value, settings) {
2
3
var td = $(row).closest('.cvrnummer');
4
5
alert(td.html());
6
7
$.post('UserAdministration/UpdateOwners', { owner: value }, function (data) {
8
alert(data);
9
});
10
}
11
12
$('.editable').editable(function (value, settings) {
13
updateOwner(this, value, settings);
14
return (value);
15
}, {
16
data: " {'mona':'moma','cecilie':'cecilie','jacob':'jacob', 'morten':'morten', 'rasmus' : 'rasmus', 'selected':'mona'}",
17
type: 'select',
18
submit: 'OK'
19
});
20
The table looks like this:
JavaScript
1
26
26
1
<table id="userTable" class="table-autofilter table-autosort" >
2
<thead>
3
<tr>
4
<th>CVR-Nummer</th>
5
<th>Firma navn</th>
6
<th class="table-filterable">Tilhører</th>
7
<th class="table-sortable:date">Oprettet</th>
8
<th>Sidst online</th>
9
<th></th>
10
<th class="table-sortable:numeric table-sortable">Besvaret (%)</th>
11
</tr>
12
</thead>
13
<tbody>
14
<tr>
15
<td class="cvrnummer"></td>
16
<td></td>
17
<td class="editable" style="text-align: center;"></td>
18
<td></td>
19
<td></td>
20
<td>Se besvarelser</td>
21
<td>
22
</td>
23
</tr>
24
</tbody>
25
</table>
26
I want to pass the value inside
JavaScript
1
2
1
<td class="cvrnummer"></td>
2
when i use AJAX to post a value, but im not sure how to get the value. Im using:
JavaScript
1
4
1
var td = $(row).closest('.cvrnummer');
2
3
alert(td.html());
4
which is returning null.
How do i get the value?
Advertisement
Answer
You should do
JavaScript
1
2
1
var td = $(row).closest('tr').find('td.cvrnummer');
2
because closest()
goes up the DOM tree, while find()
goes down. You can’t use prev()
because it returns just the preovious element