jQM - Markup enhancement partial prevention

by ken tsai

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta name="viewport" content="width=device-width"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" /> 
        <script>
            $(document).on('mobileinit', function () {
                $.mobile.ignoreContentEnabled = true;
            });
        </script>
        <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>   
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="a" data-role="header" data-enhance="false">
                <h3>
                    First Page
                </h3>
                <a href="#second" class="ui-btn-right">Next</a>
            </div>
            
            <div data-role="content" id="test-main-container">
                <a href="#" data-role="button" id="test-button">Test button 1</a>
                <!-- Every content inside this div will not be enhanced -->
                <div data-enhance="false" id="test-container">
                    <a href="#" data-role="button" id="test-button">Test button 2</a>                
                    <div>
                        <a href="#" data-role="button" id="test-button">Test button 3</a>                
                    </div>                
                </div>
                <a href="#" data-role="button" id="test-button">Test button 4</a>
            </div>
            
            <div data-theme="a" data-role="footer" data-position="fixed" data-enhance="false">
                <h3>
                    Footer
                </h3>
            </div>
        </div>   
    </body>
</html>

JavaScript

$(document).on('pagebeforeshow', '#index', function(){       
    $('<div>').attr({'data-enhance':'false','id':'dynamic-container'}).appendTo('#test-main-container');
    $('#dynamic-container').append('<a href="#" data-role="button" id="test-button">Test button 5</a>');
});