Forum Moderators: open
function change()
{
if (!document.getElementById) return null;
document.getElementById('lala').ClassName = 'test';
alert('The classname of lala is ' + document.getElementById('lala').ClassName);
}
----------
<p id="lala">Text</p>
<a href="#" onClick="change()">change</a>
If I set the class directly on the <p> element, the style shows up fine. But if I click the link, I get the alert OK, but no style change! What am I doing wrong?
Looks like the problem is with the capitalization on ClassName. The proper format is "className", with no capital C. Essentially what you are doing is setting a new variable to test, and then printing that. So the correct function should be:
function change()
{
if (!document.getElementById) return null;
document.getElementById('lala').className = 'test';
alert('The classname of lala is ' + document.getElementById('lala').className);
}
Chad