Open In App

jQuery Mobile Listview autodividersSelector 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 be using the jQuery Mobile Listview autodividersSelector option. This option is given by the “listview.autodividers” extension and the value of this option is a function that returns a string. It receives a jQuery collection object containing an element. It computes the returned string from the element. The function is called for each list item in the sequence, and a divider is created whenever the function returns a value for a list item that is different from the value it returned for the previous list item.

Syntax:

Initializing the Listview with the autodividersSelector option.

$( ".selector" ).listview({
    autodividersSelector: function ( li ) {
         var out = /* generate a string */;
         return out;
     }
});

Getting the autodividersSelector option.

var autodividersSelector = $( ".selector" )
.listview( "option", "autodividersSelector" );

CDN Link: Add the following jQuery Mobile scripts that you will need in 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 demonstrates the jQuery Mobile Listview autodividersSelector option.

HTML




<!doctype html>
<html lang="en">
  
<head>
    <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 Listview 
                autodividersSelector Option</h3>
            <div id="divID">
                <div role="main" class="ui-content">
                    <ul data-role="listview">
                        <li>
                          <a href="index.html">
                              GeeksforGeeks
                          </a>
                        </li>
                        <li><a href="index.html">GFG</a></li>
                        <li><a href="index.html">gfg</a></li>
                    </ul>
                </div>
            </div>
            <input type="button" id="Button"
                value="Value of the autodividersSelector Option">
            <div id="log"></div>
        </div>
    </center>
    <script>
        $(document).ready(function () {
            $("#divID").listview({
                  autodividers: true,
                  autodividersSelector: function ( li ) {
                    var out = "autodividersSelector";
                    return out;
                  }
            });
              
            $("#Button").on('click', function () {
                var a = $("#divID").listview(
                  "option", "autodividersSelector"
                );
                $("#log").html(a);
            });
        });
    </script>
</body>
</html>


Output:

jQuery Mobile Listview autodividersSelector option

Reference: https://api.jquerymobile.com/listview/#option-autodividersSelector



Last Updated : 30 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads