Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:18:21+00:00 2026-06-01T14:18:21+00:00

Here is some javascript that I wrote that attempts to change the theme of

  • 0

Here is some javascript that I wrote that attempts to change the theme of the header of my jQuery Mobile application. It is in the head element of my web page after jQuery mobile javascript and CSS has loaded.

$(function() {
    $("[data-role='header']").attr('data-theme', 'b'); 
});

Why is it having no effect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:18:23+00:00Added an answer on June 1, 2026 at 2:18 pm

    As it turns out, dynamically changing the theme of a header is easy since there is only a single class to change, that goes for buttons as well (if you have buttons in your header).

    //store all the classes to remove from elements when swapping their theme
    var removeClasses = 'ui-bar-a ui-bar-b ui-bar-c ui-bar-d ui-bar-e ui-btn-up-a ui-btn-up-b ui-btn-up-c ui-btn-up-d ui-btn-up-e';
    
    //when a specific page initializes, find links in the body and add an event
    //handler to the click event for them to update the header's theme
    $(document).delegate('#my-page', 'pageinit', function () {
        $(this).find('a').bind('click', function (event) {
    
            //get the new theme letter, stored in the HREF attribute of the link
            var newTheme = $(this).attr('href');
    
            //change the header's class/attr to relfect the new theme letter
            $.mobile.activePage.children('.ui-header').attr('data-theme', newTheme).removeClass(removeClasses).addClass('ui-bar-' + newTheme).children('h1').text('My Header (' + newTheme + ')');
    
            //change the header button's classes/attr to reflect the new theme letter
            $.mobile.activePage.children('.ui-header').children('a').removeClass(removeClasses).addClass('ui-btn-up-' + newTheme);
            return false;
        });
    });​
    

    Here is a demo: http://jsfiddle.net/jUgLr/1/

    After all that I guess I should make sure you know you can just add a data-theme attribute to any element to change it’s theme:

    <div data-role="page">
        <div data-role="header" data-theme="e">
            ...
        </div>
        <div data-role="content" data-theme="d">
            ...
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the situation. I have some javascript that looks like this: function onSubmit()
How to find below comment block(s) with javascript/jquery regex: /* some description here */
I'm having some trouble with the jQuery hover method. Here's the relevant JavaScript code:
I am having a problem with some javascript that I wrote that is only
I just wrote some JavaScript code that follows along with what I believe to
I have a slideshow component that I wrote in javascript using jQuery. The slideshow
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:
Here is some code on the javascript side for form-based uploads: iframe.setAttribute('src', 'javascript:false;'); I'm
Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()
So I wrote a script in PHP that requires JavaScript to run with it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.