Hey thanks for replaying Martin,
I think I should have been more descriptive about what I was hoping to
achieve. I know that I can access the document (window.document)
globally from script.
I was hoping that javascript enclosed in SCRIPT tag, might be able to
access that tag with a method or keyword (like 'this') so I could pull
custom attributes from the tag.
You can't (other than via Martin's example which has limited
application). Nor can you reliably access custom attributes across
different browsers.
The problem with getting at it globally is that I might want to have
multiple scripts in the document and I would need to create a way to
uniquely identify the SCRIPT tags. That would be fine but now the
script contained in the tag cannot be generic because it will have to
know of the identifier.
A function has no concept of the HTML script element it is contained in.
The HTML specification does not say that script elements must have an
ID or name (though these seem to be supported by at least some browsers)
and not all browsers will cope with custom element attributes.
So you can't reliably identify individual script elements other than as
members of the collection returned by document.getElementsByTagName().
But thank again for replying, it's nice to know there are people out
there willing to lend a hand...
It seems that it is leading to a very kludgey solution, probably
discouraging assistance.
What you seem to want to do is conditionally insert a script element
with some custom data. You then want a function in the script to be
able to identify the bit of custom data so it can use it.
Your attempted solution is to include the data as an attribute of the
script element, but you can't work out how to uniquely identify the
script element and you'll have cross-platform issues with custom attributes.
Perhaps you should use whatever logic you are using to insert the custom
attribute to insert the data into the page as a script variable and
determine some other scheme to associate it with the function, e.g. you
might make it a property of an object, an element of an array or just a
global variable.