jQuery position probleem in Chrome
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#button1').click(function(){
var new_col = $('#col_select_table col').eq(0);
alert(new_col.position().left);
});
$('#button2').click(function(){
var new_col = $('#col_select_table col').eq(1);
alert(new_col.position().left);
});
});
</script>
</head>
<body>
<table id="col_select_table">
<colgroup>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td>test</td>
<td>123</td>
</tr>
<tr>
<td>test</td>
<td>456</td>
</tr>
</tbody>
</table>
<input type="submit" value="kolom 1" id="button1">
<input type="submit" value="kolom 2" id="button2">
</body>
</html>
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#button1').click(function(){
var new_col = $('#col_select_table col').eq(0);
alert(new_col.position().left);
});
$('#button2').click(function(){
var new_col = $('#col_select_table col').eq(1);
alert(new_col.position().left);
});
});
</script>
</head>
<body>
<table id="col_select_table">
<colgroup>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td>test</td>
<td>123</td>
</tr>
<tr>
<td>test</td>
<td>456</td>
</tr>
</tbody>
</table>
<input type="submit" value="kolom 1" id="button1">
<input type="submit" value="kolom 2" id="button2">
</body>
</html>
klik op button 1 zou de linker positie van de eerste kolom moeten geven (10 in FF) en klik op button 2 zou de linker positie van de tweede kolom moeten geven (35 in FF). In Chrome geven ze beide 8.
Iemand enig idee wat hier de oorzaak van is en, nog belangrijker, wat ik eraan kan doen? Hoe kan ik Chrome wel de juiste positie ophalen?
Toevoeging op 29/01/2014 13:07:51:
never mind... opgelost door niet de kolom te bekijken, maar de cell in de eerst rij:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
$(document).ready(function(){
$('#button1').click(function(){
var new_col = $('#col_select_table tbody tr').eq(0).find('td').eq(0);
alert(new_col.position().left);
});
$('#button2').click(function(){
var new_col = $('#col_select_table tbody tr').eq(0).find('td').eq(1);
alert(new_col.position().left);
});
});
$('#button1').click(function(){
var new_col = $('#col_select_table tbody tr').eq(0).find('td').eq(0);
alert(new_col.position().left);
});
$('#button2').click(function(){
var new_col = $('#col_select_table tbody tr').eq(0).find('td').eq(1);
alert(new_col.position().left);
});
});
Gewijzigd op 29/01/2014 12:30:43 door Erwin H
Er zijn nog geen reacties op dit bericht.