Open In App
Related Articles

jQuery Mobile Navbar initSelector Option

Improve Article
Improve
Save Article
Save
Like Article
Like

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 14 May, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials