How to determine outer DIV tag

S

Spadar Programmer

Hello, everyone!

I'm trying to solve the next problem.
There's some HTML code. For example:

<div id="some_div">
...
<script type="text/javascript">
var oParentTag = getParentTag('some_div');
</script>
...
</div>

And my question: is there anything way to get the parent tag without
passing argument to the function in this case? Can JavaScript
atomatically determine the placement tag for executed script?

Regards, Yury Ksenevich (Spadar Programmer)
 
M

Martin Honnen

Spadar said:
<div id="some_div">
...
<script type="text/javascript">
var oParentTag = getParentTag('some_div');
</script>
...
</div>

And my question: is there anything way to get the parent tag without
passing argument to the function in this case? Can JavaScript
atomatically determine the placement tag for executed script?

If the script is global code then it is being executed while the page is
loaded and parsed meaning in that case
var divs = document.getElementsByTagName('div');
var lastDiv = divs[divs.length - 1];
should give you the div preceding the script element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top