Syntax Higlighter For Site [closed]

There are a few problems with your code above:

  • You are writing your <div> in the <head> section, which is invalid HTML
  • You are using curly “ ” quotes on your <div> class declaration, which won’t work

In addition to this, your question is incredibly vague. There don’t appear to be any ‘control commands’ in your question.

Having said that, it sounds like you’re trying to turn the text in the io class red, and some additional content in a control-commands class green.

This can be done with JavaScript’s .getElementsByClassName() method and .style property as follows:

function change() {
  document.getElementsByClassName('io')[0].style.color="red";
  document.getElementsByClassName('control-commands')[0].style.color="green";
}
<div class="io">IO</div>
<div class="control-commands">Control Commands</div>
<br />
<button onclick="change()">Change</button>

Keep in mind that .getElementsByClassName returns a Node List, so you need to access the first index of that with [0] as above.

Hope this helps!

Leave a Comment