Mohan Ram
Mohan Ram

Reputation: 8463

To add id and name for image inside tinymce?

I am trying to insert id and name for image inside tinymce.

var content=tinyMCE.get('faq_answer').getContent()+"--img tag is given here--";

I can add image inside tinymce by giving alt, title but i cant add id and name.

Upvotes: 1

Views: 1589

Answers (1)

Thariama
Thariama

Reputation: 50840

If you want to add an element at the end of your editors content i would do something like this (this way you do not have to get all the editors content and set it again):

var doc = ed.getDoc();

// create a new img element
var img = doc.createElement('img');
img.title = 'title';
img.src = '/images/my_image.gif';
img.id = 'my_id';
img.name = 'imagename';

// add the new img element to the dom
ed.getBody().appendChild(img);

Some attributes may vanish (be cleaned up) depending on the configuration of valid elements. If this configuration is not set a standard rule set will apply. You may extend this rule set using the extended valid elements option. There is a nice example concerning img elements :)

Upvotes: 1

Related Questions