Open In App

jQuery Mobile Toolbar theme Option

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. 

In this article, we will use the jQuery Mobile Toolbar theme option. The Toolbar theme option is used to set the color scheme for the toolbar. It accepts a single letter (a-z) which maps to a swatch in the theme.

Syntax:

$(".selector").toolbar({
   theme: "b"
});

 

CDN Links: First, add jQuery Mobile scripts needed for your project.

<link rel=”stylesheet” href=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”https://code.jquery.com/jquery-2.1.3.js”></script>
<script src=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js”></script>

Example 1: 

HTML




<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0" />
  
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <script src=
    </script>
  
    <script>
      function changeTheme() {
        $("#divID").toolbar("option", "theme", "b");
      }
    </script>
  </head>
  <body>
    <div data-role="page">
      <center>
        <h2 style="color:green">GeeksforGeeks</h2>
        <h3>jQuery Mobile Toolbar theme option</h3>
  
        <div id="divID" data-role="header">
          <h1>Toolbar</h1>
        </div>
  
        <button style="width:250px; margin:30px 0" 
                onclick="changeTheme();">
          Change Theme to swatch b
        </button>
      </center>
    </div>
  </body>
</html>


Output:

Mobile Toolbar theme Option

Example 2: Now let’s create a new swatch that maps to the letter “c” and use the theme option to change the theme of the toolbar.

HTML




<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible"
          content="IE=edge" />
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <script src=
    </script>
    <style>
      /* Custom swatch "c" just for toolbar */
      .ui-bar-c{
          background-color: #009245; /* toolbar background color*/
          border-color: #dddddd; /* toolbar border color*/
          color: #ffffff; /* toolbar text color*/    
        }      
    </style>
  
    <script>
        function changeTheme() {
          $("#divID").toolbar("option", "theme", "c");
        }
    </script>    
  </head>
  <body>
    <div data-role="page">
      <center>
        <h2 style="color:green">GeeksforGeeks</h2>
        <h3>jQuery Mobile Toolbar theme option</h3>
  
        <div id="divID" data-role="header">
          <h1>Toolbar</h1>
        </div>
  
        <button style="width:250px; margin:30px 0"
                onclick="changeTheme();">
             Change Theme to swatch c
        </button>
      </center>
    </div>
  </body>
</html>


Output:

Mobile Toolbar theme Option

Reference: https://api.jquerymobile.com/toolbar/#option-theme



Last Updated : 28 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads