IT戦記

プログラミング、起業などについて書いているプログラマーのブログです😚

JavaScript の in を使って要素の差分を取る

in 文の実用的な使いかた

とりあえず、 Firefox + Firebug 前提で。

link 要素ってどんな要素だっけ

じゃあ、とりあえず、<link> にあって <div> にないものを出してみよう

for (var n in HTMLLinkElement.prototype) if (!(n in HTMLDivElement.prototype)) console.log(n);
disabled charset href hreflang media rel rev target type sheet

おお。rel とか rev とか href とか持ってるんだな。ふむふむ。 getAttribute とか setAttribute とか使わなくてもいいな。

じゃあ script 要素は?
for (var n in HTMLScriptElement.prototype) if (!(n in HTMLDivElement.prototype)) console.log(n);
text htmlFor event charset defer src type

ふむふむ。 htmlFor と event が気になるな。

じゃあ iframe 要素は?
for (var n in HTMLIFrameElement.prototype) if (!(n in HTMLDivElement.prototype)) console.log(n);
contentDocument frameBorder height longDesc marginHeight marginWidth name scrolling src width contentWindow

うーん。普通。

この使いかた便利ー (*'v')