I'm doing a card flip using CSS3 and javascript on multiple divs. I'm using desssandro's 3d Card Flip but his is only using an ID and therefore one div at a time. I have several cards in one page that I want to flip. How can I do it?
Here's the desandro's script and a fiddle
http://jsfiddle.net/vanduzled/nawdpj5j/
var init = function() {
var card = document.getElementById('card');
document.getElementById('flip').addEventListener( 'click', function(){
card.toggleClassName('flipped');
}, false);
};
window.addEventListener('DOMContentLoaded', init, false);
If I make my divs a class instead of id's, the script below doesn't work:
var init = function() {
var card = document.getElementById('card');
document.getElementById('flip').addEventListener( 'click', function(){
card.toggleClassName('flipped');
}, false);
};
window.addEventListener('DOMContentLoaded', init, false);
EDIT
I created a fiddle byclassname but it doesn't work