Use navbar buttons as toggle buttons in jQuery Mobile
Hi guys,
I'm trying to use
footer navbar buttons as toggle buttons in jQuery Mobile 1.2.0, but I have a problem on Safari Mobile.
This is the HTML code for my buttons.
- <div data-role="navbar" class="navbar" data-grid="b">
- <ul>
- <li><a href="#" id="navbar-1" data-icon="custom">Navbar 1</a></li>
- <li><a href="#" id="navbar-2" data-icon="custom">Navbar 2</a></li>
- <li><a href="#" id="navbar-3" data-icon="custom">Navbar 3</a></li>
- </ul>
- </div>
And this is the JavaScript code I use to simulate toggle feature.
- var toggle1 = false;
- $("#navbar-1").on("click", function () {
- if (toggle1) {
- $("#navbar-1").removeClass("ui-btn-active");
- }
- else {
- $("#navbar-1").addClass("ui-btn-active");
- }
- toggle1 = !toggle1;
- return false;
- });
- [Repeat for navbar-2 and navbar-3]
This works correctly on Safari, Chrome and Firefox.
Every button is "independent" and the click action works like a toggle.
But on Safari Mobile, if I click on a button, it automatically deactivates all the other.
How do I prevent this default behaviour on Safari Mobile?
Thanks.