Я пытаюсь изменить все деления одного цвета на другой. Он работает с document.querySelector()
, но не с querySelectorAll. Я хотел бы изменить их все. Вот мой код:
<html>
<head>
<script >
var v;
var v1;
function link(){
v1=document.querySelector('[style*="background:black;"]');
v1.style.backgroundColor = "red";
v=document.querySelectorAll('[style*="background:black;"]');
v.style.backgroundColor = "red";
}
</script>
</head>
<body>
<div style="background:black; height:100px; width:100px;"></div>
<div style="background:blue; height:100px; width:100px;"></div>
<div style="background:black; height:100px; width:100px;"></div>
<div style="background:black; height:100px; width:100px;"></div>
<div style="background:blue; height:100px; width:100px;"></div>
<button onclick="link()" style="height:20px; width:50px;">Click </button>
</body>
</html>
Есть идеи, что я могу сделать? Спасибо!