Per Salbark
Per Salbark

Reputation: 3645

Can I get the original textarea id from within jwysiwyg?

I have some textareas:

<textarea id="temp1">Hello</textarea>
<textarea id="temp2">Hello</textarea>
...

and I initialize jwysiwyg on them:

$('#temp1').wysiwyg();
$('#temp2').wysiwyg();

I also have a custom button for saving the content. Now how can I get a hold of the original textarea dom element? (I need to distinguish between several occurances of jwysiwyg here.)

function Wysiwyg() {
  this.controls = {
    save: {
      exec: function () {
        // Magically find the id of the original textarea plx.
        ...

Thanks...

Upvotes: 0

Views: 300

Answers (1)

John
John

Reputation: 1319

$('#temp').wysiwyg($(this));

function Wysiwyg(textarea) {
  this.controls = {
    save: {
      exec: function () {
        $(textarea).val(); //return selected text area value
        // Magically find the id of the original textarea plx.
        ...

When you run the function for wysiwyg, send the selected element through to the function and call the jquery within that function from the passed in variable...

You must remember you can only use id once on the document if you have multiple text areas you can put this for applying css, if you use the $(this) reference on a clicked item then you do not need to call it by anything else:

<textarea class="tArea">Hello</textarea>
<textarea class="tArea">Hello</textarea>
 $('textarea.tArea').wysiwyg($(this));

Upvotes: 0

Related Questions