Re: first element before my div
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: first element before my div

From: Evertjan. <exjxw.hannivoort@interxnl.net>
Date: Thu Apr 06 2006 - 14:09:03 CEST

sc wrote on 06 apr 2006 in comp.lang.javascript:

> "Evertjan." wrote:
>> Try:
>>
>> <div>
>> <p>content 1 content</p>
>> <div id=myDiv2>content 2 content</div>
>> </div>
>>
>> <script type='text/javascript'>
>> document.getElementById('myDiv2').parentNode.style.display = 'none'
>> </script>
>
> The trouble is that I'm not allowed to change the structure of that
> HTML...

I would not accept an assignment with susch restrictions.

given your question:
> How to check if the first element before 'myDiv2' is a
> paraghraph ?

you could check that:

<div>
<p>content 1 content</p>
<div id=myDiv2>content 2 content</div>
</div>

<script type='text/javascript'>
alert(document.getElementById('myDiv2').previousSibling.tagName=='P')
</script>

giving, as expected, true in IE and false in FF

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Received on Mon May 1 04:45:13 2006