I want to use jQuery to grab the id from a hyperlink.
<a class="aDirectReply" id="user1234">Respond to user1234</a>
then set the content of a redactor textarea
<textarea rows="10" class="form-control" id="redactor_content" name="content"></textarea>
Here is my jQuery
$(document).ready(function()
{
var buttons = ['formatting', '|', 'bold', 'italic', 'fullscreen', '|', 'button1'];
$('#redactor_content').redactor({
focus: true,
buttons: buttons
});
$('a.aDirectReply').on("click",function(e){
var username = $(this).attr("id");
$('#redactor_content').redactor('set', '@' + username); // doesn't work
....
I've tried everything I can find on StackOverflow, including this: Textarea editor Redactor. Insert value with jQuery But nothing has worked so far.
The docs give an example:
let app = Redactor('#entry');
// insert content from outside scripts
app.editor.insertContent({ html: '<p>Hello world!</p>' });
// insert content in the plugin method
this.app.editor.insertContent({ html: '<p>Hello world!</p>' });
but all their examples result in the error "Redactor is not defined"
I want to use jQuery to grab the id from a hyperlink.
<a class="aDirectReply" id="user1234">Respond to user1234</a>
then set the content of a redactor textarea
<textarea rows="10" class="form-control" id="redactor_content" name="content"></textarea>
Here is my jQuery
$(document).ready(function()
{
var buttons = ['formatting', '|', 'bold', 'italic', 'fullscreen', '|', 'button1'];
$('#redactor_content').redactor({
focus: true,
buttons: buttons
});
$('a.aDirectReply').on("click",function(e){
var username = $(this).attr("id");
$('#redactor_content').redactor('set', '@' + username); // doesn't work
....
I've tried everything I can find on StackOverflow, including this: Textarea editor Redactor. Insert value with jQuery But nothing has worked so far.
The docs give an example:
let app = Redactor('#entry');
// insert content from outside scripts
app.editor.insertContent({ html: '<p>Hello world!</p>' });
// insert content in the plugin method
this.app.editor.insertContent({ html: '<p>Hello world!</p>' });
but all their examples result in the error "Redactor is not defined"
Share Improve this question edited Apr 4 at 20:07 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Mar 22 at 1:26 user460114user460114 1,8954 gold badges31 silver badges56 bronze badges1 Answer
Reset to default 0I found the only thing that worked. First destroy, then recreate with the new content.
$('#redactor_content').destroyEditor();
$('#redactor_content').redactor().setCode('@' + username);