Streaming live at 10am (PST)

What's wrong with this code?


#1

Here is some Jquery code I am working on:-


var clicks = 0;

$( "#mybtn").click(function() {
if(clicks == 0) {
document.querySelector("#mycard").classList.toggle("flip");
clicks++;
} else {
document.querySelector("#mycard").classList.toggle("flip");
clicks--;
}
$( "#mybtn1").click(function() {
if(clicks == 0) {
document.querySelector("#mycard1").classList.toggle("flip");
clicks++;
} else {
document.querySelector("#mycard1").classList.toggle("flip");
clicks--;
}
$( "#mybtn2").click(function() {
if(clicks == 0) {
document.querySelector("#mycard2").classList.toggle("flip");
clicks++;
} else {
document.querySelector("#mycard2").classList.toggle("flip");
clicks--;
}
$( "#mybtn3").click(function() {
if(clicks == 0) {
document.querySelector("#mycard3").classList.toggle("flip");
clicks++;
} else {
document.querySelector("#mycard3").classList.toggle("flip");
clicks--;
}
});


Is this the correct way to structure this code or is there a way to make it shorter?


#2

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.