Search code examples
twitter-bootstrapcordovaphonegap-cli

how to use div as pages in apache cordova?


Thing I am trying to achieve is as follow

  1. I want to create a single html page cordova app
  2. My page will be single, but I want to show mutiple divs as pages.. (Only divs will be toggled as pages. I dont want to add another html page.)

Is it possible? Please explain me...

following is structure which i wana achieve

<code>
<div class="main-content">
<div class="changing-content">
</div>
<div>
</code>

Solution

  • Here is a sample code for you, try and implement for yourself

    <body>
        <div id="index">
            <div onclick="showPage('page1')">Page 1</div>
            <div onclick="showPage('page2')">Page 2</div>
        </div>
        <div id="page1" style="display:none">
            This is page1
            <div class="back" onclick="showPage('index')">Back</div>
        </div>
        <div id="page2" style="display:none">
            This is page2
            <div class="back" onclick="showPage('index')">Back</div>
    </div>
    </body>
    <script>
    var ids=['page1','page2','index'];
    function showPage(pageId)
    {
        for(i=0;i<ids.length;i++)
        {
            if(pageId == ids[i])
            {
                document.getElementById(pageId).style.display = "block";
            }
            else
            {
                document.getElementById(ids[i]).style.display = "none";
            }
        }
    }
    </script>
    

    Here is a jsFiddle link