javascript - Redactor - Uncaught TypeError: Cannot read property 'insert' of undefined -
i'm trying use redactor in project. want add text editor upon button click.
the api says can this:
function inserthtml() { var html = '<h3>inserted</h3>'; $('#redactor').redactor('insert.html', html); }
well, code looks this:
<button onclick="inserthtml();">insert</button> <script type="text/javascript"> function inserthtml() { var html = '<h3>inserted</h3>'; $('.redactor-box').redactor('insert.html', html); } </script>
redactor editor:
<div class="redactor-box"> <ul class="redactor-toolbar" id="redactor-toolbar-0" style= "position: relative; width: auto; top: 0px; left: 0px; visibility: visible;"> <li> <a class="re-icon re-bold" href="#" rel="bold" tabindex="-1"></a> </li> <li> <a class="re-icon re-italic" href="#" rel="italic" tabindex= "-1"></a> </li> <li> <a class="re-icon re-deleted" href="#" rel="deleted" tabindex= "-1"></a> </li> <li> <a class="re-icon re-unorderedlist" href="#" rel="unorderedlist" tabindex="-1"></a> </li> <li> <a class="re-icon re-orderedlist" href="#" rel="orderedlist" tabindex="-1"></a> </li> <li> <a class="re-icon re-outdent" href="#" rel="outdent" tabindex= "-1"></a> </li> <li> <a class="re-icon re-indent" href="#" rel="indent" tabindex= "-1"></a> </li> <li> <a class="re-icon re-image" href="#" rel="image" tabindex="-1"></a> </li> <li> <a class="re-icon re-file" href="#" rel="file" tabindex="-1"></a> </li> <li> <a class="re-icon re-link" href="#" rel="link" tabindex="-1"></a> </li> <li> <a class="re-icon re-horizontalrule" href="#" rel="horizontalrule" tabindex="-1"></a> </li> <li> <a class="re-icon re-mathematik redactor-btn-image" href="#" rel= "mathematik" tabindex="-1"></a> </li> </ul> <div class="redactor-editor redactor-placeholder" contenteditable="true" dir="ltr" style="min-height: 300px;"> <p></p> </div> <textarea class="redactor-box" cols="40" data-redactor-options= "{"lang": "en", "fileupload": "/redactor/upload/file/", "imageupload": "/redactor/upload/image/"}" dir="ltr" id="id_body" name="body" placeholder="vsebina vprašanja.." rows= "10" style="display: none;">
error i'm getting:
uncaught typeerror: cannot read property 'insert' of undefined(anonymous function) @ redactor.js:47n.extend.each @ jquery-2.1.4.min.js:2n.fn.n.each @ jquery-2.1.4.min.js:2$.fn.redactor @ redactor.js:39inserthtml @ (index):366onclick @ (index):205
what doing wrong?
i'm going assume it's because example uses jquery id lookup, returns single element, , implementation using jquery class lookup returns array of elements.
either use: $('.redactor-box')[0]
or change element's class in question id, , use $('#redactor-box')
.
Comments
Post a Comment