I want to be able to add width to my paragraph with each click with Javascript. What am I doing wrong? Here is my code :
let button = document.querySelector("button");
button.addEventListener("click",function(e) {
let p = document.querySelector("p");
if(window.getComputedStyle(p).getPropertyValue("width")==="10px")
{
p.style.width = "10px";
p++;
}
else
{
console.log(false)
}
});
p {
box-shadow: 0 4px 8px rgb(0,0,0,0.4);
height: 40px;
width: 10px;
display: block;
}
<button>click!</button><p>my paragraph</p>