I'm still new to Jquery Mobile and definitely it's a great framework.
I hope someone could help me. I'm having issues with jquery events after ajax page loading.
The following code will work on first page load, but after visiting other pages it won't work.
JS
jQuery("#menu").tap(function () {
jQuery("ul.sub-menu").slideToggle("slow");
});
HTML
<input type="button" id="menu" value="Menu" data-icon="arrow-d"/>
<ul class="sub-menu" data-role="listview">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 1</a></li>
</ul>
I've tried using pageinit() and pageshow() but still it won't work.
Any help would be greatly appreciated.
Code in my header.php in worpdress:
<div data-role="page" id="indexPage" class="blog page">
<script type="text/javascript">
jQuery("div:jqmData(role='page'):last").bind('pageshow', function(){
//your code here - $.mobile.activePage works now
jQuery.mobile.activePage.on('tap', '.menu', function(){
alert('test');
jQuery.mobile.activePage.find('ul.sub-menu').slideToggle('slow');
});
});
</script>
<?php
//Get data theme from theme options
$options = get_option('touch_theme_options');
$theme = $options['color_option'];
?>
<div id="logo">
<a href="<?php echo home_url(); ?>"><img src="<?php bloginfo('url'); ?>/wp-content/themes/converse/images/sofrep-logo-mobile.png" alt="<?php bloginfo('title'); ?>"></a>
</div>
<div data-theme="<?php echo $theme ?>">
<input type="button" id="menu" class="menu" value="Menu" data-icon="arrow-d"/>
<ul class="sub-menu" data-role="listview">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</div>