jQuery Mobile >= 1.4
.buttonMarkup()
as well as data-role="button"
are deprecated and will be removed in 1.5. Instead, classes should be added manually to Anchor tag.
Create a function to manipulate classes of Anchor. As of jQM page events are now replaced with
pageContainer
events. The new events can't be bound to a specific page, therefore, you need to look for the Anchor inside active page.Note that
$.mobile.activePage
is also deprecated and replaced with$.mobile.pageContainer.pagecontainer("getActivePage")
.function resizeBtn() { var activePage = $.mobile.pageContainer.pagecontainer("getActivePage"); if ($(window).width() <= 480) { $("#notext.ui-btn-icon-left", activePage) .toggleClass("ui-btn-icon-notext ui-btn-icon-left"); } else { $("#notext.ui-btn-icon-notext", activePage) .toggleClass("ui-btn-icon-left ui-btn-icon-notext"); } }
Call function on
pagecontainerbeforeshow
event:$(document).on("pagecontainerbeforeshow", resizeBtn);
Call function on
throttledresize
event:$(window).on("throttledresize", resizeBtn);
Note: throttledresize
is better than resize
as it delays firing resize
event coming from the browser.
jQuery Mobile <= 1.3
You need to use .buttonMarkup()
if you're using jQuery Mobile 1.3 or lower.
$(".selector").buttonMarkup({
iconpos: "notext"
});
Resize function:
function resizeBtn() { if ($(window).width() <= 480) { $(".selector").buttonMarkup({ iconpos: "notext" }); } else { $(".selector").buttonMarkup({ iconpos: "right" }); } }
Call function on
pagebeforeshow
:$(document).on("pagebeforeshow", resizeBtn);
Call function on
resize
:$(window).on("resize", resizeBtn);