Locate the Tag where a specific function is positioned?

  • Thread starter Thomas K. Nielsen
  • Start date
T

Thomas K. Nielsen

Hi I dynamically insert some stylesheets. I want them to be placed
before some javascript is executed. I know I can add an id to the
scripttag that I want the stylesheets to be insert above, but I then
have a problem with with backward compability(need to insert that id
to many pages) and I have a problem if my colleagues forget to add
that id to the script tag.

My question is can I locate a javascript funtion - ie I have a
initPage function that I know should
always be on the page - can I locate what script tag element that
function is located in and then use that to insert the stylesheets
above that script tag? How do I locate the script tag? I cannot be
sure that the script tag is always the last on the page.

Thanks in advance
 
R

RobG

Hi I dynamically insert some stylesheets. I want them to be placed
before some javascript is executed. I know I can add an id to the
scripttag that I want the stylesheets to be insert above, but I then

You can try, but the HTML 4 specification doesn't include an id
attribute for script elements, so I would expect some browsers to not
support it.

In valid HTML, style elements should only appear in the head.
Browsers may take notice of script elements in the body, but the
results may not be what you expect).

have a problem with with backward compability(need to insert that id
to many pages) and I have a problem if my colleagues forget to add
that id to the script tag.

My question is can I locate a javascript funtion - ie I have a
initPage function that I know should
always be on the page - can I locate what script tag element that
function is located in and then use that to insert the stylesheets
above that script tag? How do I locate the script tag? I cannot be
sure that the script tag is always the last on the page.

Similar questions have been asked in the past, like "can a function
tell which script element it's in?" and the answer to that is a
qualified yes (search the archives). However, I don't think you can
do what you are after. If you explain a little further, you might get
a solution that suits.

I guess you want the style sheets added only if a particular function
is in the page. My suggestion would be to add the stylesheets to the
head using a function before calling your particular function (say
using your initPage function).
 

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
474,160
Messages
2,570,890
Members
47,423
Latest member
henerygril

Latest Threads

Top