I wanted to change the border radius of the div as the input value. can anybody please acknowledge me what is missing here.
HTML
<div id="container">
<p class="test">
Test
</p>
<input id="value" type="number" />
<input type="submit" id="submit"/>
</div>
JS
let btn=document.getElementById('submit');
let value=document.getElementById('value');
let border=document.getElementById("container").style.borderRadius
let pixelVal=value.value+"px";
btn.addEventListener('click', function(){
console.log(pixelVal);
border=value+"px"
})
4
Answers
Take a look at this code for orientation.
The input value is read in the click event:
You just need to move the pixel calculation and style changing lines inside the click event listener’s callback function.
Otherwise both of these code of lines will be executed only once, and that too before the click listener event runs.
But we want that style to be applied every-time we click submit button.
Hope it helps!
pixelVal
is moved inside the event listener. This ensures that the value of the input is read when the button is clicked and not when the script is initially loaded.Access the style property of the container element in the event listener.
be only fetched when button is clicked otherwise It will be null. Thats
why Your code is not working as you want.