Не могу понять почему картинка не увеличивается.


<img src="img/1.jpg"><br><br>
<img src="img/4.jpg"><br><br>

<script>
    let img = document.querySelectorAll('img');
    console.log(img)
    for(let i = 0; i < img.length; i++){
        console.log(img[i].src);
        img[i].onclick = inc;
               
    }

    function inc(){
        console.log('width: ' + this.width + ' height: ' + this.height);
        // this.width = this.width * 2;
        this.height = this.height * 2;
    }
</script>```

Ответы (1 шт):

Автор решения: Vladimir

Вы почти все сделали правильно, кроме того что если, у вас есть фиксированная высота в стилях, то надо менять стиль, а не саму высоту

const img = document.querySelectorAll('img');

for (let i = 0; i < img.length; i++) {
  img[i].onclick = inc;

}

function inc() {
  this.style.height = this.height * 2 + 'px';
}
img {
  height: 20px;
}
<img src="https://klike.net/uploads/posts/2019-05/1556708032_1.jpg" />

→ Ссылка