Below I will share with you an article using classList to implement the switching method of two button styles. It has a good reference value and I hope it will be helpful to everyone.
ClassList attribute methods: add();remove();toggle();
Description, on some pages we need to use two buttons to switch back and forth, as shown in the figure:
We need to use the add() and remove() methods
html part:
js part:
funcction myonclick(){ document.getElementById("mya").classList.remove("newClassName1"); document.getElementById("myaa").classList.remove("newClassName"); } function myonclick1(){ document.getElementById("mya").classList.add("newClassName1"); document.getElementById("myaa").classList.add("newClassName"); }
css part:
.login-title{ width:200px; height:200px; margin: 0 auto; background-color:antiquewhite; } .mya2{ padding: 0 20px 10px 20px; color:#FFFFFF; font-size:22px; text-decoration:none; } .mya1{ padding:0 20px 10px 20px; color:#7F4A88; font-size:22px; text-decoration:none; border-bottom:2px solid #7F4A88; } .newClassName{ padding:0 20px 10px 20px; color:#7F4A88; font-size:22px; text-decoration:none; border-bottom:2px solid #7F4A88; } .newClassName1{ padding: 0 20px 10px 20px; color:#FFFFFF; font-size:22px; text-decoration:none; }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use babel installation and configuration tutorial
How to configure the babel configuration file in vue-cli
Use node.js to implement Douyin’s automatic red envelope grabbing function
Use webpack packaging to deal with the problem of excessively large bundle.js files
How to fill in the default avatar in javascript
The above is the detailed content of How classList implements two button style switching. For more information, please follow other related articles on the PHP Chinese website!