jquery/jquery-mobile — Issue #3373: jqmData() does not set data as expected
Author: micheljansen
Created: 2012-01-03 15:06:16+00:00
State: open

In trying to manipulate the data-url property of dynamically generated pages, I was using jqmData() in order to adhere to any potential namespacing. However, it does not work as expected:

> $("#results-page").jqmData("url")
"results-page"

> $("#results-page").jqmData("url", "/results")
[

​…​

​ ]

> $("#results-page").jqmData("url")
"/results"

looking good, huh?

However, looking at the element in the DOM in the Chrome Developer Tools, reveals that the "data-url" property did not change and is still "results-page". This is in fact the case:

> $("#results-page").attr("data-url")
"results-page"

This might be kind of OK if JQM at least respected its own "shadow" property, but it doesn't:

> $.mobile.changePage("/results")
undefined
GET http://localhost:9292/results 404 (Not Found)

Proper behaviour (albeit not namespaced), can be achieved when setting the data-url property manually:

> $("#results-page").attr("data-url", "/results")
[

​…​

​ ]

Which not only sets the data-url attribute:

> $("#results-page").attr("data-url")
"/results"

But also affects the jqmData url:

> $("#results-page").jqmData("url")
"/results"

And now JQM picks the property up properly:

> $.mobile.changePage("/results")
undefined
(as you can see, there is no error 404 because jQuery properly recognises it is an "internal" pageChange).

I feel that jqmData() should set the namespaced data-url property in the DOM as expected and that this should affect internal things like pageChange behaviour in a predictable way.

P.S. This is my first jQuery Mobile bug report, please let me know if you would appreciate a different format for future reports, I'm not quite familiar with the etiquette for this project yet :)