it does, its just your thinking of how replace works is wrong, it does not do an inline change it returns the changed string, if it didnt work you would be getting an
Cannot call method 'getAttribute' of null
document.getElementById("myH1").getAttribute("class").replace("bye","NO");
should be
var change = document.getElementById("myH1").getAttribute("class").replace("bye","NO");
document.getElementById("myH1").setAttribute("class",change);