william
william

Reputation: 606

replace textarea in jquery

I'm trying to Replace a %%%VERSION%%% text, the text is coming from an tinyMCE editor.

looks like this.

$("#description textarea").val($("#description textarea").val().replace(/%%%VERSION%%%/g, STAT_VERSION_INFO));

The value of the textearea is:

<textarea rows="20" cols="117" name="description" id="description">Some code version info: %%%VERSION%%%</textarea>

But i can't make it replace anything.

Upvotes: 1

Views: 215

Answers (4)

AndreasKnudsen
AndreasKnudsen

Reputation: 3481

To select: $("#description textarea") => $("textarea#description") or just $("#description")

To do the changes:

var textarea = $("textarea#description");
var text = textarea.html().replace(/%%%VERSION%%%/g, '');
textarea.html(text);

Upvotes: 1

Josh Stodola
Josh Stodola

Reputation: 82483

Use html() for textareas...

var txt = $("#description");
txt.html(txt.html().replace(/%%%VERSION%%%/g, '');

Upvotes: 1

Eivind
Eivind

Reputation: 841

Change .val() to .html() and it works: Example here http://jsbin.com/uwidu/

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

Just replace $("#description textarea") with $("#description") or $("textarea#description"). The first selector will look for a textarea inside a DOM element with id=description, while in your case it is the textarea that has id=description.

Hope this makes sense.

Upvotes: 0

Related Questions