Home > Web Front-end > JS Tutorial > JQuery operates on class attributes to achieve button switch effect_jquery

JQuery operates on class attributes to achieve button switch effect_jquery

WBOY
Release: 2016-05-16 17:20:19
Original
1277 people have browsed it

In this article, JQuery is used to operate the class attribute to achieve the button switch effect on the page.

First define two classes:

Copy the code The code is as follows:

.controlOff{
display:inline-block;
width:130px;
height:36px;
cursor:pointer;
background-image:url("../iclass/images/ teach_off.png");
background-repeat: no-repeat;
}

.controlOn{
display:inline-block;
width:130px;
height :36px;
cursor:pointer;
background-image:url("../iclass/images/teach_on.png");
background-repeat: no-repeat;
}

Define another hyperlink tag:
Copy the code The code is as follows:



Then write the JS script to complete the switching effect:
Copy code The code is as follows:

function switchTeachControl(){
var target = $( "#teachControl");
if(target.hasClass("controlOff")){
target.removeClass("controlOff");
target.addClass("controlOn");

}else{
target.removeClass("controlOn");
target.addClass("controlOff");

}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template