This seems to work for me:
<html> <head><style> #monkey {color:blue} #ape {color:purple} </style></head> <body> <span id="monkey" onclick="changeid()"> fruit </span> <script> function changeid () { var e = document.getElementById("monkey"); e.id = "ape"; } </script> </body> </html>
The expected behaviour-changing the colour of the word "fruit".
Perhaps your document was not fully loaded when you called the procedure?
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.