I want to turn a span of text red when I click on a button. Why does the first set of code, with separate Javascript and HTML, not work... but the second set of code does?
FIRST SET (not working)
JAVASCRIPT:
function focus()
{
getElementById('redder').style.color = '#ff0000';
}
HTML:
<button id="button1" onClick="javascript:focus()">cool</button>
<span id="redder"> RED </span>
. . .
SECOND SET (working)
HTML:
<button id="button1" onClick="getElementById('redder').style.color = '#ff0000';">cool</button>
<span id="redder"> RED </span>
focus()is a native DOM function, you need to use some other name for your function.javascript:label