Why Doesn't this Work? Javascript getElementById onclick update..
About button pressed : display text and change onclick to clear() (button text also changed)
Clear (same button) pressed : go back to being ready for About to be pressed (onclick changed back to about() )
Using :
<input id="aboutButton" type="button" onclick='doAbout()' value="About">
and
function doAbout() {
document.getElementById("divabout").innerHTML = "by Ananth Chellappa<br>One Hour Design<br>Your questions answered within the hour";
document.getElementById("divabout").className="aboutcolor";
document.getElementById("aboutButton").onclick="clearAbout()";
document.getElementById("aboutButton").value="Clear";
}
function clearAbout() {
document.getElementById("divabout").innerHTML = "";
document.getElementById("divabout").className="aboutcolor";
document.getElementById("aboutButton").onclick='doAbout()';
document.getElementById("aboutButton").value="About";
}
And : About works the first time and after that, nothing works.
Root cause : it's in HTML that you need 'doAbout()'. In JS, the function is already known, so you just use the name, as in : .onclick=doAbout;
And you're done. Thanks to Parth Desai of G H Raisoni College of Engineering and Management.
Comments
Post a Comment