Search code examples
javascriptreactjsjsxgetelementbyid

Why I can't set the text with getElementById().value?


        <div className="mb-3 form-check">
            <input type="checkbox" className="form-check-input" id="exampleCheck1" />
            <label className="form-check-label" htmlFor="exampleCheck1" id="suca">
            Accetto di vedere peni
            </label>
        </div>
        <button type="submit" className="btn btn-primary" onClick={(event)=>
{document.getElementById("suca").value="lol";
props.onVamo(document.getElementById("Username").value,document.getElementById("NumeroStanza").value,event)}}> 
                    Vamo
        </button>

Why document.getElementById("suca").value="lol"; why doesn't this actually set the text to "lol"? I don't get it..


Solution

  • Besides "the react way" considerations, value is a valid attribute for inputs/textareas, labels and other html elements have innerHTML

    document.getElementById("blyat").innerHTML = "I have changed!";