JavaScript
x
4
1
<i class="icon slash eye" id="test"
2
onclick="registerFunction(); myFunction(this);"
3
style="margin-bottom:-20px;cursor: pointer;float:right;"></i>
4
Script
JavaScript
1
6
1
<script>
2
function myFunction(x) {
3
x.classList.remove("slash");
4
}
5
</script>
6
It is changing slash eye to eye but not vice versa. How can I achieve that?
Advertisement
Answer
You are just removing the class with remove
method.
Your question almost answered itself, as the solution to it is the toggle
method.
JavaScript
1
6
1
<script>
2
function myFunction(x) {
3
x.classList.toggle("slash");
4
}
5
</script>
6
With this simple change, your code should behave as you expect now.