1 year ago
#345380
Ankita Sinha
Superscript Toggle in js
I am trying to build a rich text editor from scratch.I am struggling while toggling on/off superscript.
I am using
var sel= window.getSelection()
var text=sel.toString()
var range=sel.getRangeAt(0)
document.addEventListener('changesupercript',
function({detail}){
if(isActive){
if(detail.verticalAlign='super'){
var sText=range.extractContents()
var span=document.createElement('span')
span.style.verticalAlign=detail.verticalAlign
span.appendChild(sText)
span.id='newspan'+text
span.className='supercript'
range.insertNode(span)
}
if(detail.verticalAlign='baseline'){
var children=document.getElementById(detail.active).children
for(var i=0;i<children.length;i++){
if(children[i].textContent === text){
var el=document.getElementById('newSpan'+text);
el.removeAttribute('style')
el.removeAttribute('id')
el.removeAttribute('className')
}
}
}
}
}
)
Any idea what might be going wrong
javascript
css
node.js
reactjs
rich-text-editor
0 Answers
Your Answer