Home  >  Article  >  Web Front-end  >  How classList implements two button style switching

How classList implements two button style switching

亚连
亚连Original
2018-06-09 17:22:411427browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn