Вход

Просмотр полной версии : Составление условия


RogerUP
10.06.2011, 09:45
var sps
if(document.getElementById('contentBlock').getElem entsByTagName('*').id == 'div-spasibo-torrent');
{sps = document.getElementById('div-spasibo-torrent').innerHTML;
document.getElementById('div-spasibo-torrent').style.display = 'none';
} else {sps = '<br>'};
Нужно чтобы если div с id='div-spasibo-torrent' существует в contentBlock то выполнять истину, если нет ложь.
У мя всегда получается ложь. Как исправить чтобы работал?

ksa
10.06.2011, 10:28
Как вариант...

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style type="text/css">
</style>
<script type="text/javascript">
function Go() {
var o=document.getElementById('div-spasibo-torrent')
if (o.parentNode.id=='contentBlock') alert('Ok')
}
</script>
</head>
<body onload='Go()'>
<div id='contentBlock'>
<div id='div-spasibo-torrent'></div>
</div>
</body>
</html>

Sweet
10.06.2011, 10:31
Лучше так:
var sps, divSpasiboTorrent = document.getElementById('div-spasibo-torrent');
if(divSpasiboTorrent){
sps = divSpasiboTorrent.innerHTML;
divSpasiboTorrent.style.display = 'none';
} else {sps = '<br>'};

RogerUP
10.06.2011, 11:13
Sweet, спасибо все заработало!