flip - Flipping specific cards onClick in a memory game -


so working on memory game , got cards flip nicely, whenever click flip one, flips them all. rather use methos not giving each , every card id if possible...please help.

html

    <section class="cardscontainer">         <div class="card" onclick="flip()">             <div class="front"><img src="../images/backsideblue.png"></div>             <div class="back"><img src="../images/cookie.jpg"></div>         </div>     </section>     <section class="cardscontainer">         <div class="card" onclick="flip()">             <div class="front"><img src="../images/backsideblue.png"></div>             <div class="back"><img src="../images/cookie.jpg"></div>         </div>     </section>     <section class="cardscontainer">         <div class="card" onclick="flip()">             <div class="front"><img src="../images/backsideblue.png"></div>             <div class="back"><img src="../images/cookie.jpg"></div>         </div>     </section>     <section class="cardscontainer">         <div class="card" onclick="flip()">             <div class="front"><img src="../images/backsideblue.png"></div>             <div class="back"><img src="../images/cookie.jpg"></div>         </div>     </section>     <section class="cardscontainer">         <div class="card" onclick="flip()">             <div class="front"><img src="../images/backsideblue.png"></div>             <div class="back"><img src="../images/cookie.jpg"></div>         </div>     </section> </div> 

css

.cardscontainer {     width: 230px;     height: 320px;     position: relative;     border: 1px dashed red;     -webkit-perspective: 800px;     -moz-perspective: 800px;     -o-perspective: 800px;     perspective: 800px;     margin: 20px 10px 10px 10px;     display: inline-block; } .card {     width: 100%;     height: 100%;     position: absolute;     -webkit-transition: -webkit-transform 1s;     -moz-transition: -moz-transform 1s;     -o-transition: -o-transform 1s;     transition: transform 1s;     -webkit-transform-style: preserve-3d;     -moz-transform-style: preserve-3d;     -o-transform-style: preserve-3d;     transform-style: preserve-3d;     -webkit-transform-origin: 50% 50%; } .card div {     display: block;     height: 100%;     width: 100%;     line-height: 260px;     color: white;     text-align: center;     font-weight: bold;     font-size: 140px;     position: absolute;     -webkit-backface-visibility: hidden;     -moz-backface-visibility: hidden;     -o-backface-visibility: hidden;     backface-visibility: hidden; } .card .front { } .card .back {     -webkit-transform: rotatey( 180deg );     -moz-transform: rotatey( 180deg );     -o-transform: rotatey( 180deg );     transform: rotatey( 180deg ); } .card.flipped {     -webkit-transform: rotatey( 180deg );     -moz-transform: rotatey( 180deg );     -o-transform: rotatey( 180deg );     transform: rotatey( 180deg ); } 

js

function flip() {     $('.card').toggleclass('flipped'); } 

the function show not javascript, jquery. in jquery, $('.card') means "all elements class 'card'". need attach single onclick() function each of card objects flips itself.

try changing html onclick="flip(this)", , change flip function change element passed it:

function flip(e) { e.toggleclass('flipped'); } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -