jQuery Mobile: Apply Style for dynamically created Content
Question by Guest | 2015-05-18 at 12:07
I am using jQuery Mobile for a Web-App. On some pages, I am dynamically loading some content depending on the user input and selection.
However, there is a problem with this dynamically loaded content: the jQuery Mobile Styles for the graphical user interface elements are not applied. For example, this affects input boxes, input select boxes but also the normal Listview or the Collabsible Set.
Apparently, the styling is applied when first loading the page and it has to be repeated after new contents has been loaded. Is there any possibility to manually execute this styling again?
Related Topics
Fonts for Windows, Linux and Mac on the Web
Article | 0 Comments
Lord's Prayer in 20 other Languages
Info | 0 Comments
Delphi/Lazarus: Create TabSheet on PageControl dynamically
Tutorial | 0 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
Delphi/Lazarus: Catch CTRL+C in Memo or Edit and Change Clipboard Content
Tutorial | 0 Comments
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
jQuery: Show or hide DIV-Container depending on Checkbox State
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You cannot execute the functions .trigger("create") or .enhanceWithin() on the new elements in order to apply the style.
For example, if you have loaded dynamic content into the DIV box with the ID "divid", you can use the following procedure:
With this, all elements within the DIV "divid" will be styled again. The function .trigger("create") will do the same, but this function is marked as depreciated since jQuery Mobile version 1.4, so it is better to use .enhanceWithin() instead.
If you would like to have all in one line, you can do this:
Our new content is stored in the variable newHTML. We are adding this content to the DIV box "divid" and afterwards we are refreshing the style.
It is also possible to address single elements, for example:
With the first line, for example, we are updating the menu of a select box which can be done after adding new elements. The example above updates all listviews and with using the third example, we unable to refresh or collapsible sets of the class "myclass".
2015-05-18 at 12:27