html - How to inject type attribute into all script tags via javascript -



html - How to inject type attribute into all script tags via javascript -

i want know how query script tags , set random attribute. have tried not work:

document.getelementsbytagname("script")[0].setattribute("data-foo", "bar");

it matches first script tag. (no jquery please. love it, not now. needs cross-browser queryselectorall won't work).

edit:

okay, turns out, pure-javascript query selectors select things they're loaded (as kolink pointed out , thesystem explained). have add together script set's attributes after other script tags.

one possibility have other scripts written dynamically page using document.write.

this classic case document.write useful.

// in main/powerhouse // list of script sources var scripts = ["script1.js", "script2.js", "script3.js"] (var = 0; < scripts.length; i++) document.write('<scr', 'ipt type="text/javascript" src="', scripts[i], '"></scr', 'ipt>');

now scripts written after current running script, , loaded synchronously expected.

javascript html

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -