30/07/2015 Retour d’expérience sur ce procédé : mis en place sur un projet et pour des raisons qui restent obscures, le code n’a tout simplement pas fonctionné… Je me suis tourné vers une solution alternative consistant à stocker les URLs dans des variables et à les répercuter sur les liens ou boutons sur lesquels les clics sont délégués :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
jQuery(document).ready(function(){ var linkPrevChapter = jQuery('a.link-prev-chapter').attr('href'); var linkNextChapter = jQuery('a.link-next-chapter').attr('href'); jQuery('.mobile-conseil-bottom-nav .prev-chapter').attr('href', linkPrevChapter); jQuery('.mobile-conseil-bottom-nav .next-chapter').attr('href', linkNextChapter); if(jQuery('.link-sommaire-left').length == 1){ jQuery('.mobile-conseil-bottom-nav .prev-chapter').attr({"href": "#", "disabled": "disabled"}); } if(jQuery('.link-sommaire-right').length == 1){ jQuery('.mobile-conseil-bottom-nav .next-chapter').attr({"href": "#", "disabled": "disabled"}); } }); |
Source : Click on an element triggers the click on another element [JQuery]
1 2 3 4 5 6 7 8 |
jQuery(document).on('click', 'button.prev-chapter', function(event) { event.preventDefault(); jQuery('a.link-prev-chapter').click(); }); jQuery(document).on('click', 'button.next-chapter', function(event) { event.preventDefault(); jQuery('a.link-next-chapter').click(); }); |
Source : http://stackoverflow.com/questions/773639/how-can-i-simulate-an-anchor-click-via-jquery.
1 2 3 4 5 6 |
jQuery(function(){ jQuery('#thickboxButton').click(function(e){ e.preventDefault(); jQuery('#thickboxId').click(); }); }); |
1 2 |
<input id="thickboxButton" type="button" value="Click me"> <a id="thickboxId" href="myScript.php" class="thickbox" title="">Link</a> |
Fonctionne bien avec des liens (élément HTML ) (source : Why can’t I click() links in jQuery?) :
1 2 3 |
$('li.js-mobile-product-sort-by-date').on('click', function(){ window.location = $('.TriProduct li[data-facetcodename^="sortable_date"] a.nameFilter').attr('href'); }); |