<p>For my small wiki application, I mostly need to have the textarea used to edit the contents to use soft (or virtual) wrapping. However, in some cases, not wrapping the content would be preferable. I thought I would do this by simply having a button to turn off wrapping. Here is the simplified code:</p>

<pre><code>  &lt;form name="wikiedit" action="[[script_name]]" method="post"&gt;
    &lt;textarea name="content" rows="25" cols="90" wrap="virtual"&gt;[[content]]&lt;/textarea&gt;
    &lt;input type="button" onclick="document.wikiedit.content.wrap='off';" value="No Wrap"&gt; &amp;nbsp;
    &lt;input type="submit" value="Save"&gt;
  &lt;/form&gt;
</code></pre>

<p>It works with IE, but not with Firefox or Opera. How should I do this?</p>

According to
the HTML 4.01 spec
,
```
wrap
```
isn't a valid attribute for
```
<textarea>
```
s which would explain why it's so difficult and strange. It looks as though Firefox actually does use the
```
wrap
```
attribute, but it won't let you change it.
I do have a solution though! It's pretty awful, but here it is. Completely replace the textarea with a new one.
```
```
// this is the onclick handler for your button
document.getElementById("nowrapButton").onclick = function() {
  var oldOne = this.form.content;  // the old textarea
  var newOne = document.createElement('textarea'); // the new textarea
  var attrs = ['name', 'rows', 'cols']; // these are the attributes to keep
  for (var i = 0; i < attrs.length; ++i) {
    // copy the attributes to the new one
    newOne.setAttribute(attrs[i], oldOne.getAttribute(attrs[i]));
  }

  // toggle the wrapping on and off
  if (oldOne.getAttribute('wrap') != 'off') {
    newOne.setAttribute('wrap', 'off');
  }

  // copy the text over
  newOne.value = oldOne.value;

  // add the new one
  oldOne.parentNode.insertBefore(newOne, oldOne);
  // get rid of the old one
  oldOne.parentNode.removeChild(oldOne);
  return false;
};
```
```
Here's a working version of this you can play with:
http://jsbin.com/ugepa
As usual, this'd be much nicer in jQuery. :)