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: [on] <switchable@gmail.com>
Date: Thu Apr 06 2006 - 14:02:15 CEST

sc wrote:
> I've got such structure of the part of the site:
>
> <p>content content</p>
> <div id=myDiv1>content content</div>
>
> <p>content content</p>
> <div id=myDiv2>content content</div>
>
> No I want to hide let's say 'myDiv2'. So I write in JS:
>
> document.getElementById('myDiv2').style.display = 'none'
>
> And now, how to hide also the paragraph which is before the 'myDiv2' div ?
> How to check if the first element before 'myDiv2' is a paraghraph ?
>
> Regards,
> sc

Tried "previousSibling" ?

var somediv = document.getElementById("myDiv2");
var sibbling = somediv.previousSibling;

Note that it might select a "textNode" if you have whitespaces at odd
places.
Received on Mon May 1 04:45:10 2006