Rama
Rama

Reputation: 73

add attribute to anchor tag in tinymce

I want to add an attribute to the anchor tag through tinymce

The current text I have is

<p><a id="1212" title="abc" href="../abc" target="_blank">Test</a></p>

Required output is

<p><a id="1212" title="abc" href="../abc" sampletest="true" target="_blank">Test</a></p>

I just want to add an attribute sampletest="true" to the existing anchor tag

The following will add a class, but I want to add an attribute as above required output.

$scope.tinymceOptions.style_formats = [
{ title: 'test', selector : 'a', classes: 'sampletest'}
];

Upvotes: 1

Views: 3355

Answers (1)

Gaurav
Gaurav

Reputation: 902

You can use

tinyMCE.dom.setAttrib('Element', 'String', 'String');

Here,

Element: DOM element, element id string or array of elements/ids to set attribute on.

String :Name of attribute to set.

String: Value to set on the attribute of this value is falsy like null 0 or '' it will remove the attribute instead.

For example:

// Sets an attribute to all paragraphs in the active editor
tinyMCE.activeEditor.dom.setAttrib(tinyMCE.activeEditor.dom.select('p'), 'class', 'myclass');

// Sets an attribute to a specific element in the current page
tinyMCE.dom.setAttrib('mydiv', 'class', 'myclass');

Upvotes: 2

Related Questions