I am trying to make javascript to increase the width of one (or more than one )square if its width is above certain pixel... the problem here is that I have multiple divs with the same class so how can I make javascript change the width of the one that has it's width increased only I TRIED EVERYTHING BUT OF NO USE .... and thanks alot ...
HERE IS MY CODE :
<head>
<style>
body {
overflow-x: auto;
white-space: nowrap;
}
.test1 {
background: blue;
height: 157px;
width:321px;
margin:5px;
display: inline-block
}
</style>
</head>
<body>
<div class="test1" ></div> <div class="test1" ></div> <div class="test1" ></div> <div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<br>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1", id="change" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<div class="test1" ></div>
<script src="java.js"></script>
</body>
JAVASCRIPT :
function changewidth() {
var x = document.querySelectorAll(".test1");
if (x.style.width > '321px') {
x.style.width = '500px'
}
}
changewidth();
test1totest2and set the good width in the css