How can I change the class name of a div when I click on it? For instance:
<div class="first_name" onclick="changeClass();" id="first_name"></div>
I want to change it as follows when the user clicks on a div
<div class="second_name" onclick="changeClass();"></div>
I wrote JavaScript as:
<script language="javascript"> function change_autorefreshdiv(){ var NAME = document.getElementById("first_name") NAME.className="second_name" } </script>
It only works for the first instance. This is when loading the page, if I click on it, first_name
will be changed to second_name
. But clicking on it again, it will not return second_name
to first_name
.
source share