Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Скрыть/показать строки таблицы (https://javascript.ru/forum/dom-window/71777-skryt-pokazat-stroki-tablicy.html)

Янковиц 11.12.2017 20:44

Скрыть/показать строки таблицы
 
Разметка:
<table class="form-table no-border">
	<tbody>
		<tr class="parent">
			<th scope="row">Яндекс.Деньги<span class="description"></span></th>
			<td>
				<label class="switch_wrap">
					<input name="option[ym]" id="ym" class="parent" value="1" type="checkbox">
					<div class="switch"><span class="bullet"></span></div>
				</label>
			</td>
		</tr>
		<tr>
			<th scope="row">Телефон</th>
			<td>
				<label class="switch_wrap">
					<input name="option[ymphone]" id="ymphone" class="" value="1" type="checkbox">
					<div class="switch"><span class="bullet"></span></div>
				</label>
			</td>
		</tr>
		<tr>
			<th scope="row">Телефон</th>
			<td>
				<label class="switch_wrap">
					<input name="option[ymphone]" id="ymphone" class="" value="1" type="checkbox">
					<div class="switch"><span class="bullet"></span></div>
				</label>
			</td>
		</tr>
	</tbody>
</table>


Скрипт:
var $ = jQuery;
$(document).ready(function(){
	var _this = $('.switch_wrap .parent');
	_this.change(function(){
		if (_this.attr('checked')) {
			_this.parents('.parent').nextAll('tr').fadeOut();
		} else {
			_this.parents('.parent').nextAll('tr').fadeIn();
		}
	});
})


Стили:
.form-table tr{
display: none;
}
.form-table .parent{
display: block !important;
}

Подскажите, почему не работает скрипт?

Янковиц 11.12.2017 20:46

Кликая по чекбоксу с классом parent, нужно скрывать или показывать tr ниже tr с чекбоксом.

рони 11.12.2017 20:51

Янковиц,
if (_this.prop('checked'))

Янковиц 11.12.2017 20:53

Спасибо. Не увидел этот момент.


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