Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

jQuery Mobile Navbar initSelector Option

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 be using the jQuery Mobile Navbar initSelector option. The value of this option is a selector string that picks elements on the basis of the value of this option and explicates the stated Navbar widgets on every element of the following list.

Syntax: 

  • Initializing navbar with the specified initSelector option.
$( "Selector" ).navbar({ initSelector: "div.custom" });
  • Setting the initSelector option.
$( "Selector" ).navbar( "option", "initSelector", "div.custom" );
  • Getting the initSelector option.
var initSelector = $( "Selector" ).navbar( "option", "initSelector" );

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

<link rel=”stylesheet” href=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css”>
<script src=”//code.jquery.com/jquery-3.2.1.min.js”></script>
<script src=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js”></script>

Example: This example describes the jQuery Mobile Navbar initSelector option.

HTML




<!doctype html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
"width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css">
    <script src=
"//code.jquery.com/jquery-3.2.1.min.js">
    </script>
    <script src=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js">
    </script>
</head>
  
<body>
    <center>
        <div data-role="page">
            <h1 style="color:green;">
                GeeksforGeeks
            </h1>
            <h3>jQuery Mobile Navbar initSelector Option</h3>
            <div id="divID">
                <div data-role="header">
                </div>
                <div role="main" class="ui-content">
                </div>
                <div data-role="footer">
                    <div data-role="navbar">
                        <ul>
                            <li><a href="#" class="ui-btn-active">GFG</a></li>
                            <li><a href="#">gfg</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <input type="button" id="Button" 
                   value="Value of the initSelector Option">
            <div id="log"></div>
        </div>
    </center>
    <script>
        $(document).ready(function () {
            $("#divID").navbar({
                initSelector: ":jqmData(role='navbar')"
            });
            $("#divID").navbar("option", "initSelector", ":jqmData(role='navbar')");
            $("#Button").on('click', function () {
                var a = $("#divID").navbar("option", "initSelector");
                $("#log").html(a);
            });
        });
    </script>
</body>
</html>


Output:

 

Reference: https://api.jquerymobile.com/navbar/#option-initSelector


My Personal Notes arrow_drop_up
Last Updated : 14 May, 2022
Like Article
Save Article
Similar Reads
Related Tutorials