回答編集履歴
1
html
test
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
`querySelectorAll('[style="background-color:red"]')`で、style属性が`"background-color:red"`の要素に限定して取得することができます。
|
2
2
|
|
3
|
+
例
|
4
|
+
```html
|
5
|
+
<div style="background-color:red">red</div>
|
6
|
+
<p style="background-color:red">red</p>
|
7
|
+
<h3>---</h3>
|
8
|
+
```
|
3
9
|
```javascript
|
4
10
|
const targetElems = document.querySelectorAll('[style="background-color:red"]');
|
5
11
|
console.log(targetElems); // [div, p]
|