Forum Moderators: open
If you are only going to have one script tag in your document, or you know that the script your trying to find will always be the second (or third...) then you can find it by using
document.getElementsByTagName('script')[[i]index[/i]]. Andrew
Ok then I put together this possible solution it may not be the best it isn't the most attractive:
[pre]<html>
<head>
<script type="text/javascript">
function findPreviousSibling(){
var id = "temp" + Math.floor(Math.random()*100000);
document.write('<span style="display:none;" id="' + id + '"></span>');
var r = document.getElementById(id).previousSibling;
var c = 0;
return r.previousSibling.previousSibling;
}
</script>
</head>
<body>
<p>test</p>
<script type="text/javascript">
alert(findPreviousSibling());
</script>
</body>
</html>[/pre] Andrew