Скрыть несколько блоков по клику
Привет, есть код
<div><input type='checkbox' name='line[0]' />123</div> <div><input type='checkbox' name='line[1]' /><span id="GG">1234</span></div> <div><input type='checkbox' name='line[2]' />4567</div> <div><input type='checkbox' name='line[3]' />999</div> Как сделать так чтобы при клике на кнопку элемент где id="GG" не было видно, причем хочется скрыть весь блок <div><input type='checkbox' name='line[1]' /><span id="GG">1234</span></div> Спасибо! |
Цитата:
$('#GG').parent().hide();
|
Цитата:
<head>
<meta charset="utf-8">
</head>
<body>
<div><input type='checkbox' name='line[0]' />123</div>
<div><input type='checkbox' name='line[1]' /><span id="GG">1234</span></div>
<div><input type='checkbox' name='line[2]' />4567</div>
<div><input type='checkbox' name='line[3]' />999</div>
<script>
document.getElementById("GG").previousElementSibling.onclick = function(){
this.parentNode.style.display='none'
}
</script>
</body>
|
Цитата:
parentNode http://www.fpublisher.ru/documentati...cs#hparentnode |
Цитата:
Цитата:
|
Цитата:
автор сказал :Как сделать так чтобы при клике на кнопку элемент где id="GG" не было видно, причем хочется скрыть весь блок как я понял берем элемент span с id="GG" выбираем его (рядом стоящий) чекбокс, по клику на него скрываем весь блок. |
Цитата:
|
Цитата:
|
Цитата:
|
Цитата:
<head>
<meta charset="utf-8">
</head>
<body>
<div><input type='checkbox' name='line[0]' />123</div>
<div><input type='checkbox' name='line[1]' />1234</div>
<div><input type='checkbox' name='line[2]' />4567</div>
<div><input type='checkbox' name='line[3]' />999</div>
<script>
var inp = document.querySelectorAll("input[type='checkbox']");
[].forEach.call(inp, function(inp) {
inp.addEventListener('click', function() {
this.parentNode.style.display='none';
});
});
</script>
</body>
так? |
| Часовой пояс GMT +3, время: 07:07. |