I am working on a rich text editor and have succeeded so far. I made a separate .js file to use it as a plugin.
Now I want to use this plugin by assigning it a class name via a .cshtml file. But it does not seem to work, I was looking for relevant answers, and they said that using document.getElementsByClassName would solve my problem.
Read this code and tell me what went wrong?
Text editor .js -
var richTextEditor = document.getElementsByClassName("text-editor"); richTextEditor.contentDocument.designMode = 'ON'; $('#strong').live('click', function () { richTextEditor.contentDocument.designMode = 'ON'; richTextEditor.contentDocument.body.contentEditable = true; richTextEditor.contentDocument.execCommand('bold', false, null); richTextEditor.focus(); });
Cshtml file -
<script src="/js/Texteditor.js" type="text/javascript"></script> <script src="/js/jquery.js" type="text/javascript"></script> <div id="strong" class="command btn"><i class="icon-bold icon-black"></i></div> <iframe id="edtNoteCreate" class="text-editor" name="DisplayNote" style="width:430px;height:150px;">@((Model.Note != null ? Model.Note : ""))</iframe>
source share