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.
この jQuery セレクターに相当するものは何だろうか: $(".className tagName")javascript で? 誰でも私を助けることができますか?前もって感謝します。
$(".className tagName")
最新のブラウザーではdocument.querySelectorAll、まったく同じ文字列セレクターを使用できます。この関数はコレクション (正確には NodeList コレクション) を返しますが、jquery コレクションと混同してはいけません。
document.querySelectorAll
いずれにせよ、何らかの理由で jquery を使用したくないが、セレクターを集中的に使用したい場合は、Sizzleのようなセレクター ライブラリを使用することをお勧めします。
従来の方法かもしれませんが、JavaScript でdocument.getElementByTagNameを使用してから、反復処理を行って、一致するクラス名を持つ正確な要素を取得できます。
ロジック全体を 1 つの関数にまとめ、これを再利用して、jQuery を使用せずにすばやく結果を取得してください。document.getElementByTagName() の結果をグローバル変数に永続化すると、パフォーマンスが向上します。
乾杯