I'd like to be able to change the cents of li
by the input of MudarCentavos
. But by setting Id
in li
and treating Id
by Id
, because this list will be dynamic, then more than 3 values may come.
Note: 2 Decimal places
function MudarCentavos() {
var getCentavos = document.getElementById('getCentavos').value
console.log(getCentavos)
}
<label>Mudar centavos</label>
<input type="text" maxlength="2" pattern="([0-9]|[0-9]|[0-9])" id="getCentavos">
<button onclick="MudarCentavos()">Submit</button>
<ul>
<li>24.50</li>
<li>10.2</li>
<li>43</li>
</ul>
Example
If I put in the input 99
and give Submit
, the output of the values will be:
24.99
10.99
43.99
Thank you!