javascriptdocumentframetitleparent-node

Get parentNode of Current Script Tag


Is there any way to get the parent node of current script tag. I wanted to assign id attribute to the script tag but found that it does not support standard attributes.

Actually I want to get the title of a document inside a frame and document.title is returning the title of the webpage.


Solution

  • I believe this is what you are looking for:

    document.currentScript.parentNode
    

    The documentation for Document.currentScript says:

    Returns the element whose script is currently being processed.