Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   не работает nextElementSibling в теге <Table> (https://javascript.ru/forum/dom-window/63126-ne-rabotaet-nextelementsibling-v-tege-table.html)

salerius 19.05.2016 14:30

не работает nextElementSibling в теге <Table>
 
Добрый день.
Нужно при нажатии курсором в Input, чтобы все три CheckBoxа которые стоят сразу после Input - очищались.

Делаю так

<table border="1">
<tr>
	<td>
		<input name="placeName" class="my-input-place_0" value="placeValue" onfocus="on(this)">
	</td>
	<td class="tdRow emptyCheckbox">
		<input id="id_op" name="opVod" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;"> 
		<input id="id_op" name="opKy" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
		<input id="id_op" name="opLi" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
	</td>
</tr>

<tr>
	<td>
		<input name="placeName" class="my-input-place_1" value="placeValue" onfocus="on(this)">
	</td>
	<td class="tdRow emptyCheckbox">
		<input id="id_op" name="opVod" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;"> 
		<input id="id_op" name="opKy" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
		<input id="id_op" name="opLi" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
	</td>
</tr>
</table>



function on(a) {
var opvo=a.nextElementSibling;
var opki=opvo.nextElementSibling;
var opli=opki.nextElementSibling;

opvo.checked=false;
opki.checked=false;
opli.checked=false;
}


Проблема в том что если я возьму и помещу весь блок хтмл в теги <table> </table> - nextElementSibling перестаёт работать.
В чём проблема?
Заранее спасибо

Dilettante_Pro 19.05.2016 15:16

salerius,
<table border="1">

<td>
<input name="placeName" class="my-input-place_0" value="placeValue" onfocus="on(this)">
</td>
<td class="tdRow emptyCheckbox">
<input  name="opVod" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;"> 
<input  name="opKy" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
<input  name="opLi" type="checkbox" class="rfield empty_field_checkbox" align="center" style="width: 26%;">
</td>

</table>

<script>
function on(a) {
var opvo=a.parentElement.nextElementSibling.firstElementChild;
var opki=opvo.nextElementSibling;
var opli=opki.nextElementSibling;

opvo.checked=false;
opki.checked=false;
opli.checked=false;
}
</script>

Цитата:

три CheckBoxа которые стоят сразу после Input
Они не сразу, они в разных ячейках.
Сначала подняться на td, перейти к следующему td, найти первого ребенка и т.д.

И id одинаковых не должно быть

salerius 19.05.2016 16:35

Спасибо за ответ - а можан точнее.
А то запутался
Спасибо


Часовой пояс GMT +3, время: 03:56.