最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to run a javascript script before the other ones? - Stack Overflow

programmeradmin1浏览0评论

Do you know if it is possible to make sure that a JavaScript script site is ran first in a web page?

For the context, I'm trying to tag every span before another library (just like cufon) kicks in and messes with the original content. Since it's not possible to use onLoad() on spans, it's the only way I can see to do that on the client side.

Do you know if it is possible to make sure that a JavaScript script site is ran first in a web page?

For the context, I'm trying to tag every span before another library (just like cufon) kicks in and messes with the original content. Since it's not possible to use onLoad() on spans, it's the only way I can see to do that on the client side.

Share Improve this question edited Aug 31, 2022 at 10:50 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 8, 2012 at 10:48 RobRob 2,7866 gold badges32 silver badges39 bronze badges 1
  • Have you tried including the script just after where your <span>s are in your HTML, or anywhere before your other scripts? – Bojangles Commented Jun 8, 2012 at 10:51
Add a ment  | 

2 Answers 2

Reset to default 6

Order of precedence is determined by the order in which things load.

  1. Head tag scripts (in the order they are listed)
  2. Scripts & other event attributes in the order they appear in the code.
  3. Body onLoad

I did have #2 & #3 mixed up - to clarify the body onLoad event fires after the entire body (scripts included) loads

Also, scripts altering <span> tags will have no effect if placed in the head tag (unless they are a function) since the script runs when it is loaded, and when the head loads, the body & span tags haven't loaded yet.

Place <script> tag in page source after content that you need to modify, but before any other scripts. Scripts run in same order that their tags appear on page.

发布评论

评论列表(0)

  1. 暂无评论