Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

How do I add a paragraph's width with each click with Javascript?

$
0
0

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>

Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>