Skip to content

Instantly share code, notes, and snippets.

@bitifet
Created October 21, 2014 21:25
Show Gist options
  • Save bitifet/06a2c045ade9554b1c6e to your computer and use it in GitHub Desktop.
Save bitifet/06a2c045ade9554b1c6e to your computer and use it in GitHub Desktop.
Convert any anchor with the .back-btn class in "intelligent" back buttons in jquery-mobile framework.
// Implement .back-btn class bassed (self-explainatory) functionality for anchors.
$(".back-btn").each(function(){
var btn = $(this); // me (.back-btn)
var pageId = btn.closest("div[data-role='page']").attr("id"); // My page id.
$('a[href="#' + pageId + '"]').each(function(){ // Anchors linking my page.
var srcLink = $(this);
var srcPageId = srcLink.closest("div[data-role='page']").attr("id"); // Their page id.
// Awesome magic!! ;-)
srcLink.on("click", function(){
btn.attr("href", '#' + srcPageId);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment