Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
[itemtype='http://schema.org/Offer']現在のページに属性を持つHTMLタグがある場合、Javascriptで可能な限り最速の方法で検出しようとしています。
[itemtype='http://schema.org/Offer']
if(document.querySelectorAll("*[itemtype='http://schema.org/Offer']").length){ alert("It is there!"); }
IE 7 以下ではSizzleを使用してください。これは jQuery 用の同じ CSS セレクター エンジンですが、それらの派手なものは一切ありません。
document.querySelectorAll = document.querySelectorAll || Sizzle;
jQueryセレクターの速度に関する関連情報をいくつか紹介します。明らかに、セレクターで ID を使用するのが最も速いように見えますが、それができない場合は、スコープを特定のタグのグループに制限することも役立ちます
..編集.. 要素を選択するだけでよい場合は、sizzleエンジンを使用できます。これは jquery が内部的に使用するものであり、jQuery の肥大化について心配する必要はありません。