2

I have this:

    <title>MyMobile</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>

<title>My Mobile</title>

<style type="text/css"> 
    table { width:100%; }
    table caption { text-align:left;  }
    table thead th { text-align:left; border-bottom-width:1px; border-top-width:1px; }
    table th, td { text-align:left; padding:6px;border: inset 1pt} 
</style> 

If I go to the page manually my table elements look fine. I can see the borders, etc. If I got the page from another mobile page the page loads ok but the table CSS stuff never get applied. No styles. Hit referesh, styled.

What is going on?

Thank you.

edit: not loading my javascript either. refresh. all works again.

edit: does same if I hit the back button to another page. not everything loads.

3
  • If I understood your question properly the CSS is not displaying on a jQuery-loaded page. I have had the same problem recently and you might want to try something like this. He reloaded the CSS without reloading the entire page: stackoverflow.com/questions/2024486/… Commented Dec 9, 2011 at 22:27
  • All JavaScript must be in the first page that jQM loads Commented Dec 10, 2011 at 0:18
  • @PhillPafford I do not understand. Do you have a link that explains this? Commented Dec 10, 2011 at 0:53

1 Answer 1

7

Whenever you have A tags, JQM by default uses AJAX to load those pages - and then ignores everything but whatever is included inside the div data-role=page element.

You have 3 options:

  1. You can either tell JQM to always disable AJAX (by setting ajaxEnabled to false) and load pages as "normal browsers" do - this will re-load also all javascript includes, stylesheets, etc...

  2. You can include all the different div data-role=page inside ONE .html page, that way JQM will need to load nothing else when navigating between pages

  3. You can still use AJAX and load external files, but then you'll need to include all your code (HTML/CSS/JS) INSIDE the DIV itself. Note that at this option you'll need to attach to different events (pageinit/beforeshow/show/hide) and not $.ready (since JQM will then take care of that and the DOMContentReady is not actually going to fire.

You can read all about this in the documentation

Hope this helps...

Sign up to request clarification or add additional context in comments.

2 Comments

as always... it depends ;) basically on the number of total pages your app has, how big each one is, and how slow you want your users to navigate between pages. Personally, I find option #2 usually the easiest and most performant
if this answers your question, please mark as Answer for the other members! 10x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.