问题
I have followed html:
<tr>
<td class="link" onClick="detil_iklan(this)">AD2188914</td>
<td>Seluruh Zona 468x60 - Global Gambar</td>
<td>41.100.000</td>
<td>4.440.100</td>
<td>0.005</td>
<td>Rp. 1.250.000</td>
</tr>
<tr class="border_bottom detil_iklan" style="display:none">
<td colspan="6">AD2188914</td>
</tr>
I have followed javascript:
function detil_iklan(e) {
var parent = e.parentNode;
var next = parent.nextSibling;
if (next.style.display == 'none') {
next.style.display = '';
} else {
next.style.display = 'none';
}
alert("fas");
}
what wrong with my code ? When call detil_iklan(e), alert is not called. Can anyone help me ?
thanks,
回答1:
Added a function to find next sibling
function detil_iklan(e) {
var parent = e.parentNode;
var next = get_nextsibling(parent);
if (next.style.display == 'none') {
next.style.display = '';
} else {
next.style.display = 'none';
}
}
//function to find next sibling
function get_nextsibling(n) {
x = n.nextSibling;
while (x.nodeType != 1) {
x = x.nextSibling;
}
return x;
}
DemoFiddle
来源:https://stackoverflow.com/questions/22588071/javascript-nextsibling-is-not-working