I tried to add class to CSS when clicking a button and it works on desktop but it doesn't works on mobile phone
here is my code :
<script>
document.getElementById('logbit').addEventListener('click',function() {
document.getElementById('logf').classList.add('bg');
})
</script>
CodePudding user response:
I do not know why you are using a jquery tag if you are not using jquery in your code.
But since you asked about jquery I will give a jquery answer.
$("#logbit").click(function() {
$("#logf").addClass("bg");
})
That should be working on phone aswell as pc.
CodePudding user response:
See if this works:
<style>
.bg {
background-color: blue;
}
</style>
<input type="button" value="Button" id="button">
<script>
document.querySelector("#button").onclick = function () {
document.body.classList.add("bg");
}
</script>
