jQuery Mobile: Collapsible Set With Different Icons

This entry is part 30 of 73 in the series jQuery Mobile

Let’s build a collapsible list of content with different icons.

Collapsible Icon Set
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Collapsible Set</h1></div>
    <br>

    <div data-role='collapsibleset' data-theme='a' data-content-theme='a' data-collapsed-icon='arrow-r' data-expanded-icon='arrow-d'>
        <div data-role='collapsible'>
            <h3>Icon set on the set</h3>
            <p>Specify the open and close icons on the set to apply it to all the collapsibles within.</p>
        </div>
        <div data-role='collapsible'>
            <h3>Icon set on the set</h3>
            <p>This collapsible also gets the icon from the set.</p>
        </div>
        <div data-role='collapsible' data-collapsed-icon='gear' data-expanded-icon='delete'>
            <h3>Icon set on this collapsible</h3>
            <p>The icons here are applied to this collapsible specifically, thus overriding the set icons.</p>
        </div>
    </div>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

In the above script, we have this line:

<div data-role='collapsibleset' data-theme='a' data-content-theme='a' data-collapsed-icon='arrow-r' data-expanded-icon='arrow-d'>

It will use arrow icon when in collapsed mode and a down arrow icon when in expanded mode.

The default icons of collapsible headings can be overridden by using the data-collapsed-icon and data-expanded-icon attributes, either at the collapsibleset level or on any of its collapsibles individually.

In line 23, we have used data-collapsed-icon=’gear’ to override the arrow icon set up in line 14.

Series Navigation<< jQuery Mobile: A Form Inside A Collapsible Content List
jQuery Mobile: Filterable List >>