Is there a way using javascript and HTML to change the color of a span? For example:
<span onLoad="document.getElementById('test').style.color = 'red';" id="test">test</span>
But that doesn’t seem to work.
Quick update: This is just a precursor to the actual problem that I’m trying to solve. Basically I’m inside a CMS that only allows for in place HTML editing. That means that I don’t have access to the head to add custom javascript functions etc. What I’m trying to do is make an inline function that takes the date specified (in a span for example) and then colorizes it based on some in-line js logic.
Spans do not have an “onload” event. If you want to run that when the page loads, add a script block on the
<head>with the following code:Considering your clarification about not having access to the header: you can add a
<script>block anywhere below the elements you’re targeting, and it works. If possible, add a single script block before</body>(or as far down as possible). Another possibility is just adding a class from the CMS editor, and define that class on an external CSS file. Yet another possibility are inline CSS styles, as suggested on defau1t’s answer.