jquery-mobilejquery-mobile-button

How to remove button text responsively in JQuery Mobile


I'm very new to Jquery & jquery mobile. I'm resizing a button so it's responsive to window size. To be more specific, i'm changing it from iconpos="left" to iconpos="notext" to remove the text on small windows. I found the following function, which works for me.

$(window).on("throttledresize", function() {
  var smallButtons = $(window).width() <= 480;
  $('#menu_toggle').toggleClass('ui-btn-icon-notext', smallButtons);
  $('#menu_toggle').toggleClass('ui-btn-icon-left', !smallButtons);
});

But it only works on the window resizing. Obviously, I'd also like it showing the correct size on pageload, not just resizing. I found the code below, but I don't know how put them both into 1, more succinct bit of code.

$("#page_id").on("pageshow" , function() {
 The Function
});

Solution

  • 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.

    Note: throttledresize is better than resize as it delays firing resize event coming from the browser.

    Demo


    jQuery Mobile <= 1.3

    You need to use .buttonMarkup() if you're using jQuery Mobile 1.3 or lower.

    $(".selector").buttonMarkup({
      iconpos: "notext"
    });
    

    Demo