How to determine outer DIV tag

Discussion in 'Javascript' started by Spadar Programmer, Jun 20, 2007.

  1. 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)
     
    Spadar Programmer, Jun 20, 2007
    #1
    1. Advertising

  2. Spadar Programmer wrote:

    > <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.




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 20, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bradsalmon
    Replies:
    6
    Views:
    625
    richard
    Oct 13, 2006
  2. Mc Lauren Series
    Replies:
    3
    Views:
    1,292
    Neredbojias
    Feb 13, 2010
  3. M Wells
    Replies:
    0
    Views:
    141
    M Wells
    Oct 6, 2004
  4. visu
    Replies:
    4
    Views:
    302
  5. Tom Y
    Replies:
    1
    Views:
    226
    Elegie
    Jul 12, 2011
Loading...

Share This Page