Change text inside textarea jQuery

I am trying to change the text inside a text field using id="code" , but $("#code").val(newtext) does not work. What could be the problem? I use CodeMirror to highlight text inside if that matters Thanks

+4
source share
2 answers

textarea does not have a value attribute; so you better use the .text() function

 $("#id").text(newValue); 

Update: Well, I had this problem once in my old project, but after switching to .text (), it works (got a solution from here ). I know that .val could also be applied, but if you encounter such problems (this may be due to the compatibility of your browser, jquery version ...), and you are sure that your selector code is correct, then select either path (val or text)

+2
source
 encodeURIComponent($("#code").val(newtext)) 
0
source

All Articles