JQUERY/CKEDITOR : Récupérer la valeur d’un textarea

Comment récupérer la valeur d’un textarea en JQUERY quand on utilise CKEDITOR.
En temps normal pour récupérer la valeur d’un input ou d’un textarea par exemple, on utilise :
HTML : <textarea id="commentaire">Bidule</textarea>
JQUERY : $("#commentaire").val('');
Mais avec la bibliothèque CKEDITOR qui rajoute une surcouche, il faut utiliser cette méthode :
HTML : <textarea id="commentaire">Bidule</textarea>
JQUERY : CKEDITOR.instances['commentaire'].getData();
Code complet :
<textarea id="commentaire">Bidule</textarea>
<script src="ckeditor/ckeditor.js"></script>
<script>
$(function () {
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('rapport_contenu')
})
</script>
<script>
$(function () {
var moncommentaire = CKEDITOR.instances['rapport_contenu'].getData();
alert(moncommentaire);
})
</script>
English translation
JQUERY / CKEDITOR: Retrieve the value of a textarea
How to get the value of a textarea in JQUERY when using CKEDITOR. Normally to retrieve the value of an input or a textarea for example, we use:
HTML : <textarea id="commentaire">Bidule</textarea>
JQUERY : $("#commentaire").val('');
But with the CKEDITOR library which adds an overlay, you have to use this method:
HTML : <textarea id="commentaire">Bidule</textarea>
JQUERY : CKEDITOR.instances['commentaire'].getData();
Full code:
<textarea id="commentaire">Bidule</textarea>
<script src="ckeditor/ckeditor.js"></script>
<script>
$(function () {
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('rapport_contenu')
})
</script>
<script>
$(function () {
var moncommentaire = CKEDITOR.instances['rapport_contenu'].getData();
alert(moncommentaire);
})
</script>
Source : https://stackoverflow.com/questions/37361606/how-to-get-ckeditor-textarea-value-using-jquery/37361646
Deposer un commentaire