1

Is there any way to add the variable into the jQuery command like this :

var id = 10;
var msg = CKEDITOR.instances.contentedit+id.getData();

I expect

CKEDITOR.instances.contentedit10.getData();

from the code above

But it does not work for me and caused the errors as it does not properly add the variable to the command.

j08691
  • 204,283
  • 31
  • 260
  • 272
H.J. Frost
  • 303
  • 1
  • 3
  • 14

1 Answers1

5

You can do this:

var msg = CKEDITOR.instances["contentedit" + id].getData();

The [ ] operator does exactly the same thing as ., but it allows any expression instead of just an identifier.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • @BhojendraNepal because it would be an error if it were not. – Pointy Feb 02 '15 at 18:14
  • @BhojendraNepal no, "contentedit" is part of the name of the property. It has to be a string. The only variable involved is "id". – Pointy Feb 02 '15 at 18:15
  • A variable, appended to the string "contentedit" to create the full name, thus the quotes. – ssube Feb 02 '15 at 18:15