lundi 28 décembre 2015

Different actions for each card with jQuery in WordPress

I want each card of this plugin to take the user to some specific page so I tried the following code which works fine:

jQuery(document).on('click', '.fc_card-container', function() {
    alert('clicked!');
    location.href = 'http://www.google.com';
});

However, I have 10 cards (.fc_card-container) and I am supposed to set a different destination page for each one. How can I do that?

UPDATE: Someone told me to do the following, but the extra data-url property disappears.. :(

On each fc_card-container element you could add an extra data-* property to store the URL that the click event should go to, something like this:

<div class="fc_card fc_auto fc_flipping-right" data-url="http://ift.tt/gbk8l4" data-direction="right"

data-autoflip="2000" data-start="1000">

jQuery(document).on('click', '.fc_card-container', function() {
    window.location.assign($(this).data('url'));
});

Thanks !



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire