LoginSignup
0
0

More than 5 years have passed since last update.

querySelectorAll でブラウジング中に不要な要素を気軽に消したりする

Posted at
  • Chrome とか適当に開発コンソールが開けるブラウザでコンソールを開く
  • おもむろに以下のようなコードを実行すればいらない要素を消せる
    • セレクタや消す条件は適宜読み換える
(() => {
    // リスト一覧の要素を querySelectorAll で取得
    const listItems = document.querySelectorAll('table.mTop5 > tbody > tr');

    listItems.forEach(listItem => {
        // 条件に一致する要素があれば削除する
        // 今回の例だと、特定の label 要素に任意の文字列が含まれていなければ削除
        const labelElem = listItem.querySelector('label[title="メモリ規格"]');
        if (! labelElem) { return; }

        const text = labelElem.innerHTML.trim();
        if (text.indexOf('DDR3') < 0) {
            listItem.parentNode.removeChild(listItem);
        }
    });
})();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0