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.

jQuery Mobile: A Form Inside A Collapsible Content List

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

In jQuery Mobile, we can have a form inside a collapsible content list.  This is done by using the fieldset tag with data-role=’collapsible’.

The fieldset is put one level under the form tag.

Inside the collapsible form, there is a text-input field and 3 checkboxes for selection.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.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.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Collapsible</h1></div>
    <br>

    <form>
        <fieldset data-role='collapsible'>
            <legend>Form Inside A Collapsible</legend>
            <label for='textinput_id'>Text Input:</label>
            <input type='text' name='textinput' id='textinput_id' placeholder='Text input' value=''>

            <div data-role='controlgroup'>
                <input type='checkbox' name='checkbox_n1' id='checkbox_id1'>
                <label for='checkbox_id1'>One</label>
                <input type='checkbox' name='checkbox_n2' id='checkbox_id2'>
                <label for='checkbox_id2'>Two</label>
                <input type='checkbox' name='checkbox_n3' id='checkbox_id3'>
                <label for='checkbox_id3'>Three</label>
            </div>
        </fieldset>
    </form>

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

jQuery Mobile: Icons For Collapsible Set

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

jQuery Mobile provides a set of icons that we can use.

The default icons of collapsible headings can be overridden by using the data-collapsed-icon and data-expanded-icon attributes.

In the example below, we have used data-collapsed-icon=’carat-d’ for the down arrow and data-expanded-icon=’carat-u’ for the up arrow.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.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.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Collapsible</h1></div>
    <br>

    <p>Collapsible Icons</p>

    <div data-role='collapsible' data-collapsed-icon='carat-d' data-expanded-icon='carat-u'>
        <h4>Heading</h4>
        <ul data-role='listview' data-inset='false'>
            <li>Read-only list item 1</li>
            <li>Read-only list item 2</li>
            <li>Read-only list item 3</li>
        </ul>
    </div>

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

Notice that in line 18, I have used data-inset=’false’.

By default collapsibles have an inset appearance. To make them full width without corner styling add the data-inset=’false’ attribute to the element.

jQuery Mobile: Collapsible Expanded

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

In jQM collapsibles, you can have the content expanded as a default.

This is done by using the attribute data-collapsed=’false’.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.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.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Collapsible</h1></div>
    <br>

    <p>Collapsible Expanded</p>

    <div data-role='collapsible' data-collapsed='false'>
        <h4>Heading</h4>
        <ul data-role='listview'>
            <li><a href='#'>List item 1</a></li>
            <li><a href='#'>List item 2</a></li>
            <li><a href='#'>List item 3</a></li>
        </ul>
    </div>

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

The list has a href which is supposed to be a link and so it will automatically create a > arrow on the right hand side of the list.

jQuery Mobile: Collapsible with 2 themes

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

jQuery Mobile provides two themes, theme a and theme b.

In this example, we use 2 themes to separate out the the header and the content.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.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.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Collapsible</h1></div>
    <br>

    <p>Collapsible With Themes</p>

    <div data-role='collapsible' data-theme='b' data-content-theme='a'>
        <h4>Heading</h4>
        <p>I'm the collapsible content with a themed content block set to 'a'.</p>
    </div>

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

The line that specified the 2 themes is

<div data-role=’collapsible’ data-theme=’b’ data-content-theme=’a’>