Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  109] [ 6]  / answers: 1 / hits: 26102  / 11 Years ago, thu, march 21, 2013, 12:00:00

I am working on rich text editor and did well till now. I've made a separate .js file to use it as a plugin.



Now i want to use this plugin by giving it a class name through .cshtml file.But it doesn't seem to work, i've searched for related answers and they said using document.getElementsByClassName will solve my problem.



Please go through 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>

More From » jquery

 Answers
8

Just take the first item of the matched nodes; it's a NodeList but can be dereferenced like an Array.



var richTextEditor = document.getElementsByClassName(text-editor)[0];

[#79446] Wednesday, March 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;