I am trying to dynamically change the style of an element .item
in my page but I am getting error
Cannot read properties of null (reading 'style')
Here is my Style
.item {
flex: 0 0 calc(12% - 20px);
background: #36bf00;
color: white;
margin: 10px 10px -20px 10px;
}
And this is my jQuery
$(document).keydown(function(e){
var imgsize = 12;
if (e.keyCode == 38) { // Up
console.log("up")
var NewImgsize = imgsize + 0.5;
var NewStyle = '0 0 calc(' + NewImgsize + '% - 20px';
document.getElementById('item').style.flex = NewStyle;
return false;
}
if (e.keyCode == 40) { //Down
console.log("down")
return false;
}
})
Any idea what I am missing?
Thanks