Question

I have an issue that I have been unable to solve in a way that appears correct.

I have a fiddle that illustrates my issue:

http://jsfiddle.net/adamsurfari/qsP52/

<body>
<div data-role="page" id="index">
    <div data-theme="a" data-role="header">
        <a href="#" class="ui-btn-left" data-icon="back">BACK</a>
        <h3>
            You Selected
        </h3>
    </div>

    <div data-role="content" id="test-main-container">
        <div data-role="collapsible-set" data-inset="false">

            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>FROG</h3>
                <ul data-role="listview">
                    <li><a href="#">BULL FROG</a></li>
                </ul>
            </div><!-- /collapsible -->
            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>TOAD</h3>
                <ul data-role="listview">
                    <li><a href="#">FAT</a></li>
                </ul>
            </div><!-- /collapsible -->
            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>REPTILE</h3>
                <ul data-role="listview">
                    <li><a href="#">Aardvark</a></li>
                    <li><a href="#">Alligator</a></li>
                    <li><a href="#">Ant</a></li>
                    <li><a href="#">Bear</a></li>
                    <li><a href="#">Beaver</a></li>
                    <li><a href="#">Cougar</a></li>
                    <li><a href="#">Dingo</a></li>
                </ul>
            </div><!-- /collapsible -->

        </div>
    </div>
</div>
</body>

What I would like to do is save on the accordion the Family and the Option of the accordion menu. For instance if I select the option BULL FROG

I would have var selectedAnimal = BULL FROG, selectedFamily = FROG

However I am having trouble creating the selectors to do this task.

Was it helpful?

Solution

Here's a working example: http://jsfiddle.net/Gajotres/4uzKp/

$(document).on('pagebeforeshow', '#index', function(){       
    $(document).on('click', '[data-role="listview"] li', function(){       
        var selectedAnimal = $(this).find('.ui-btn-text a').text();
        var family = $(this).parent().parent().parent().find('.ui-btn-text').first();
        family.find('span').remove();
        family = family.text();
        alert("Selected animal = " + selectedAnimal + ", selected family = " + family);
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top