Need help getting and using the id of a textarea so that I can replace it with a ckEDITOR.

So here is the html output:

NOTE: This is the output of a foreach loop, for every database result, this is the html output and the textarea ID is a number generated from the id of the row.

<div class="blogtest" id="514">
<form action="process/updatepost.php" class="updatepost" method="post">
<input type="button" class=edity value="Edit">
// SOME BUTTONS
<br>
<div class="text">
<div class="buildtext" id="514">3</div>
<div class="editor">
<textarea name="muffin" id="516" class="ckeditor">3</textarea>
</div>
</div>
</form>
</div>

And here is the jQuery im using:

$(document).on('click','.edity',function(){
var editorID = $(this).find('.ckeditor').attr("id")
CKEDITOR.replace(editorID);
});

This doesnt work, I'm not the most advanced with jQuery so not sure why. But i get a type b is undefined error in my console log.

Also just to note; this works:

CKEDITOR.replace('516');

but the text areas are loaded dynamically in a foreach loop and I can't be creating a replace code for 1000's of editors...

有帮助吗?

解决方案

You are looking for the .checkeditor element from the .edity element. Instead you can do:

$(document).on('click','.edity',function() {
    var editorID = $(this).parents('.blogtest').find('.ckeditor').attr("id");
    CKEDITOR.replace(editorID);
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top