How can I change a div class name when clicking on it? Eg:
<div class="first_name" onclick="changeClass();" id="first_name"></div>
I want to change it as follows, when a user clicks on the div
<div class="second_name" onclick="changeClass();"></div>
I wrote the JavaScript as:
<script language="javascript">
function change_autorefreshdiv(){
var NAME = document.getElementById("first_name")
NAME.className="second_name"
}
</script>
It's working for the first instance only. That is on page load, if I click on it, the first_name
gets changed into second_name
. But clicking on it again, it won't revert the second_name
to first_name
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…