How can I change the background color of a tag on mouse click using jQuery. I have some code but that code did not work.
My code:
HTML:
<a href="javascript:void(0)" onclick="changeColor('dashboard')">Dashboard</a> <a href="javascript:void(0)" onclick="changeColor('dashboard-2')">Dashboard 2</a>
Script:
<script type="text/javascript"> function changeColor(){ $(this).css("color","#0089e2"); } </script>
Define some class in your tag. Follow the example code and apply it.
HTML:
<a href="javascript:void(0)" onclick="changeColor('dashboard')" class="dashboard">Dashboard</a> <a href="javascript:void(0)" onclick="changeColor('dashboard-2')" class="dashboard-2">Dashboard 2</a>
Script:
<script type="text/javascript"> function changeColor(col){ $('.dashboard,.dashboard-2').css('color',''); $('.'+col).css("color","#0089e2"); } </script>
This code will help you to Change background color on Mouse Click using jQuery. Thanks for asking here.
Question and answer is powered by AnsPress.io