Andrei Ivanov
Andrei Ivanov

Reputation: 659

Change text inside textarea jQuery

I'm trying to change the text inside the textarea with id="code" but $("#code").val(newtext) doesn't work.. What could be the problem? I'm using CodeMirror for highlighting text inside, if this matters Thanks

Upvotes: 4

Views: 5145

Answers (2)

Amir
Amir

Reputation: 4111

encodeURIComponent($("#code").val(newtext))

Upvotes: 0

Thai Tran
Thai Tran

Reputation: 9935

textarea does not have the value attribute; therefore, it better for you to use .text() function

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

Update: Well, I had this problem once in my old project, but after changing to .text(), then it works (got solution from here). I know that .val could be applied, too, but if you get trouble like this (it could be because of your browser compatibility, version of jquery...) and you are sure that your selector code is correct, then choose either way (val or text)

Upvotes: 2

Related Questions