简体   繁体   中英

How to remove div tag?

I have a plugin that allows me to remove the style from the div. I would like to remove the div tag too.

For the moment the plugin realizes this action :

<div class="GCO9_TDM"><p>text</p></div>  --> <div><p>text</p></div>

This is the code of my plugin :

 CKEDITOR.plugins.add( 'supprimerDivision', { icons: 'supprimerDivision', init: function( editor ) { editor.addCommand( 'supprimerDivision', { exec: function( editor ) { var element = editor.getSelection().getStartElement(); while (element) { if (element.getName() == 'div') { element.setAttribute('class', ''); break; } element = element.getParent(); } } }); editor.ui.addButton( 'supprimerDivision', { label: 'supprime la division', command: 'supprimerDivision', toolbar: 'insert' } ); } }); 

Thanks, have a good day.

EDIT : my html code

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="cache-control" content="no-cache"> <title>Editeur</title> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> <!-- emplacement de ckeditor --> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <form action="enregistrementBDD.php" method="post"> <textarea id="editor" name="editor"> </textarea> <script> CKEDITOR.replace( 'editor', { //remplace le textarea par une instance de ckeditor height: 600, //taille de la fênetre allowedContent: true, //permet de définir des règles de contenu autorisé (true désactive le filtre) //startupOutlineBlocks: true, //autorise le plugin showblock a être actif dès le lancement toolbarCanCollapse: true, //permet de cacher la barre d'outil via un bouton situé en bas à droite des menus extraPlugins: 'espace,'+ 'ckeditor_wiris,'+ 'dropdownmenumanager,'+ 'raccourciClavier,'+ 'supprimerStyle,'+ 'supprimerDivision,'+ 'GCO12_DocIll,'+ 'SLT2_Num_XXX1_DocIll,'+ 'STI1_Titre_XXX1_DocIll', //fullPage: true, //page HTML complète avec balise <html>, <head>, <body>... } ); </script> </form> </body> </html> 

I had already tried this code but it works now, here is the solution

 CKEDITOR.plugins.add( 'supprimerDivision', { icons: 'supprimerDivision', init: function( editor ) { editor.addCommand( 'supprimerDivision', { exec: function( editor ) { var element = editor.getSelection().getStartElement(); while (element) { if (element.getName() == 'div') { element.setAttribute('class', ''); element.remove("div"); break; } element = element.getParent(); } } }); editor.ui.addButton( 'supprimerDivision', { label: 'supprime la division', command: 'supprimerDivision', toolbar: 'insert' } ); } }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM