my favorite

2012/02/29

[notes] to insert elements via javascript

shorthand
// style element
var d = document,
h = d.getElementsByTagName('head')[0],
s = d.createElement('link');

s.rel = "stylesheet";
s.href = "css-URL";
s.type = "text/css";
h.appendChild(s);
one liner
var d=document,h=d.getElementsByTagName('head')[0],s=d.createElement('link');s.rel="stylesheet";s.href="css- URL";s.type="text/css";h.appendChild(s);

// script element
var d = document,
h = d.getElementsByTagName('head')[0],
s = d.createElement('script');

s.href = "js-URL";

h.appendChild(s);
one liner
var d=document,h=d.getElementsByTagName('head')[0],s=d.createElement('script');s.href="js-URL";h.appendChild(s);

No comments:

BIO

Taipei, GuTing, Taiwan

huang47 | personal

huang47 | personal