I am using jQuery Mobile's PageShow event to set the width of certain input elements. If I load the page directly (i.e. through the URL) everything works as expected.
If I load the page through the standard ajax navigation system (i.e. an in-app link), I get the 'hello' alert and the correct width of the 'span.add-on', but the 'div.content-padd' element gets a width of zero? The 'div.content-padd' is a container element for all the other elements in the page and gives them some padding etc. All JS is loaded in the of my Rails layout template.
I don't know what is going on here. My code is as per below:
$(document).bind('pageshow', function() {
alert('hello')
$('.add-on').addClass('ui-corner-all');
//Set the width of the input following the appends or prepends to the remaining space
var containerWidth = $('div.content-padd').width();
console.log('container width:' + containerWidth);
var appendsAndPrepends = '.input-prepend, .input-append';
$(appendsAndPrepends).each(function () {
var remainingSpace = containerWidth - $(this).find('span.add-on').outerWidth();
console.log('span width' + $(this).find('span.add-on').outerWidth());
$(this).find('div.ui-input-text').outerWidth(remainingSpace);
});
});