2

I have a contenteditable DIV element, and I don't want to have CSS pasted, basically only it only pastes into innerText, but not innerHTML. I'm not using any library, just pure Javascript. Currently, if I were to copy some CSS text from a site, and then paste it into my div element, the style comes with it as well. I want it so if I were to paste it, the CSS wouldn't come, or make it so the CSS gets overriden by the font / color from a oninput event, that I put for the div element's class. So, how would I do this?

CSS for DIV element:

.mystyle {
    border:4px solid gray;
    background-color: #00000070;
    color: white;
    font-family: 'Courier New', Courier, monospace;
    width: 1245px;
    height: 200px;
    padding: 10px;
    font-size: 14px;
    text-shadow: 3px 3px #3f3f3f;
    text-align: justify;
  }

HTML Snippet:

    <div class="mystyle" contenteditable="true" id="input" 
    oninput='//what to put here?'></div>
SomePerson
  • 1,171
  • 4
  • 16
  • 45
  • 1
    Does this answer your question? [Contenteditable allowing only plain text](https://stackoverflow.com/questions/34764304/contenteditable-allowing-only-plain-text) – Asteroids With Wings Jul 07 '20 at 21:42
  • Your question is not very clear. Could you provide an example of what text you might paste in? as well as which part of the example text you would want removing? – A Friend Jul 07 '20 at 21:52
  • @AFriend It's clear. See https://jsfiddle.net/shjofa37/. OP doesn't want the styling brought in. They want a non-rich-text paste into a contenteditable element. – Asteroids With Wings Jul 07 '20 at 21:55
  • @AsteroidsWithWings Agree to disagree I guess. @SomePerson Would a ` – A Friend Jul 07 '20 at 22:03
  • I tried a `
    – SomePerson Jul 07 '20 at 22:21
  • Yeah that sounds like a good approach. – Asteroids With Wings Jul 07 '20 at 22:36
  • This might help: https://stackoverflow.com/questions/58756641/how-to-set-css-properties-to-element-but-not-to-innerhtml – Tyler Lewis Jul 07 '20 at 22:47