I have a div element like below:
<div id="showHideSideBar">
<button class="btn btn-sm btn-primary mx-2" id="showSideBar" onclick="myFunction()">
<i class="data-feather" data-feather="chevrons-right"></i>
</button>
</div>
And with in the same document, I have my JavaScript as per following:
<script type="text/javascript">
function myFunction() {
var content = document.getElementById("showHideSideBar");
var btn = document.getElementById("showSideBar");
var rot = 180;
btn.addEventListener("click", function() {
content.style = 'transform: rotate(' + rot + 'deg)';
rot += 180;
});
}
</script>
For above, I got the help from this thread.
Problem: When I click the button first time, there is no rotation at all. Second click flips it 180 degrees. Now third click onwards results in no rotation at all again. If someone needs a full look at the entire html, its here.
Expected: On every click the button should rotate 180 degrees.
What I am missing here?