-2

Here is the piece of code which contains two CSS elements. del and ins

I want to include the whole CSS code into Javascript... But the code is one level above my experience...

Here is the CSS code:

del {
    text-decoration: none;
    color: #b30000;
    background: #fadad7;
}
ins {
    background: #eaf2c2;
    color: #406619;
    text-decoration: none;
}

And here is the piece of code which contains those classes:

convertChangesToXML: function(changes) {
  var ret = [];
  for (var i = 0; i < changes.length; i++) {
    var change = changes[i];
    if (change.added) {
      ret.push("<ins class='diff'>");
    } else if (change.removed) {
      ret.push("<del class='diff'>");
    }

    ret.push(escapeHTML(change.value));

    if (change.added) {
      ret.push('</ins>');
    } else if (change.removed) {
      ret.push('</del>');
    }
  }
  return ret.join('');
},

How to include CSS into Javascript here?

I don't want a separate CSS file ... Because I'm using a third party app called Storyline to create a web page and it's a lot easer to run a javascript code there without a css file

Sara Ree
  • 3,417
  • 12
  • 48

1 Answers1

0

You can set any CSS on any DOM element using the JavaScript style property.

document.getElementById("el").style.color = "blue"

I suppose there are valid reasons to do this, but you may want to ask if it's efficient to set all of your CSS in your script files.

Chris B.
  • 5,477
  • 1
  • 12
  • 30