4

I am using jQuery Mobile in my project, and I ran into this problem.

Uncaught TypeError: Cannot read property 'options' of undefined 

It seems to not throw this error if I only had one page, but when I had two or more pages, after I triggered the pagecreate trigger event on all pages, this error appears.

Some answers on SO suggests that jQuery 2.x might be the reason because jQuery Mobile does not seems to work well with it. But I am using 1.9.1 and jQuery Mobile 1.3.1. They should work together.

Any ideas?

Here's a demonstration of the problem: http://jsfiddle.net/DerekL/V4qGQ/

4
  • How do you trigger pagecreate and when?
    – Omar
    Sep 29, 2013 at 0:15
  • @Omar - I triggered pagecreate after I am done applying the template header and footer into all the pages. Sep 29, 2013 at 0:16
  • Trigger pagecreate on active page only, you don't need to trigger it on other pages. Appended items into dom will be enhanced before page is shown. Edit: try this now jsfiddle.net/Palestinian/V4qGQ/1 I'm using iPad, I don't have console log. Edit: trigger it on active page only if you are appending header, footer, panel and items into panel.
    – Omar
    Sep 29, 2013 at 0:17
  • @Omar - Thanks! It does fixes the problem. You might want to post it as an answer so to help others who also run into this problem. Sep 29, 2013 at 0:24

2 Answers 2

3

Using enhancement methods such as .trigger('pagecreate') should be only used on active page.

$.mobile.activePage.trigger('pagecreate');

Also, use .trigger('pagecreate') when dynamically adding major parts into current active page: Header, Footer, navbar, Panel as well as when adding items to a panel, which require enhancement.

0

The pagecreate event is triggered by jQuery mobile itself.

Triggered when the page has been created in the DOM (via ajax or other) but before all widgets have had an opportunity to enhance the contained markup

Written in API docs jQueryMobile

3
  • Did you read my code? I have dynamically added things into the DOM and thus I have to trigger the pagecreate event to re-apply the formatting. Sep 29, 2013 at 0:14
  • Think I had a similar problem in past so I think in that case you need to trigger "create" event instead $("#pageId").trigger("create");
    – Bernhard
    Sep 29, 2013 at 0:25
  • Thanks but I figure out if I only trigger it for the active page it works. Sep 29, 2013 at 0:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.