1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta charset="utf-8"> |
---|
5 | <title>A Simple Page with CKEditor</title> |
---|
6 | <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.6.0/ckeditor.js"></script> --> |
---|
7 | <script src="ckeditor.js"></script> |
---|
8 | </head> |
---|
9 | <body> |
---|
10 | <p> |
---|
11 | <input type="button" id="replace" value="Replace question" onclick="replaceQuestion();"> |
---|
12 | </p> |
---|
13 | <div name="editor1" id="editor1"> |
---|
14 | <p> Some text...</p> |
---|
15 | <question id="myQ"> |
---|
16 | <answer> More text...</answer> |
---|
17 | </question> |
---|
18 | </div> |
---|
19 | <script> |
---|
20 | var editorElement = CKEDITOR.document.getById( 'editor1' ); |
---|
21 | editorElement.setAttribute( 'contenteditable', 'true' ); |
---|
22 | editor = CKEDITOR.inline( 'editor1' ); |
---|
23 | editor.config.allowedContent = true |
---|
24 | var replaceQuestion = function() { |
---|
25 | var sel = editor.getSelection(); |
---|
26 | var questionElement = CKEDITOR.document.getById( 'myQ' ); |
---|
27 | sel.selectElement(questionElement); |
---|
28 | editor.extractSelectedHtml(); |
---|
29 | editor.insertHtml('<choice>Some other text</choice>'); |
---|
30 | } |
---|
31 | </script> |
---|
32 | </body> |
---|
33 | </html> |
---|