Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:32:08+00:00 2026-06-16T15:32:08+00:00

I have a jQuery Mobile Navbar with two tabs: <div data-role=navbar> <ul> <li><a href=#

  • 0

I have a jQuery Mobile Navbar with two tabs:

<div data-role="navbar">
  <ul>
    <li><a href="#" class="tab ui-btn-active">Inbound</a></li>
    <li><a href="#" class="tab">Outbound</a></li>
  </ul>
</div>

When a tab is clicked, I want to

  • do nothing if it’s already the active tab,
  • do something if the tab clicked becomes the new active one.

According to the documentation, the active tab has class ui-btn-active, so I listen for clicks and see if that class is present on the clicked button:

$('.tab').click(function() {

  if ( $(this).hasClass('ui-btn-active') ) {
    // already active, do nothing
    console.log("already active");
  } else {
    // newly active, do something
    console.log("newly active");
  }
});

This has worked perfectly for months, but I see now that it is entirely dependent on the timing of when the active class is removed from one and added to the other, relative to when the if is evaluated. Now, after some unrelated code changes, it works as before on desktop browsers, but on mobile browsers, I only get already active, regardless of which button is clicked — i.e. the if happens too late.

What is the smartest way to do this? Can someone explain the sequence of events, and how the inconsistent ordering of events can happen? Is click the right listener to be using for touchscreen devices?

EDIT:

I tried listening for the bubbled event on the parent using .on() and inspecting the event object, hoping the class list it contains would be more accurate, but the behavior is the same:

$('ul').on('click','a',function(event) {
  alert(event.currentTarget.classList.contains('ui-btn-active'));
});

clicking on the inactive tab returns false on desktop browsers, as hoped, and true on mobile browsers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:32:09+00:00Added an answer on June 16, 2026 at 3:32 pm

    IMHO click is perfectly fine for this purpose and you can simply use a variable to track the active tab. Here is jsFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created bottom fixed tabs using jquery mobile data-role=navbar inside a JQ footer.
I have a navigation bar like this <div id=top data-role=navbar data-type=horizontal> <ul> <li><a href=#a>A</a></li>
Round corner tab in jQuery Mobile I have come across navbar in jquery mobile
I have a single page jQuery Mobile app with four data-role='pages' in place; so,
I have a jquery mobile list. This list is populated with data. I want
I have a small jQuery Mobile site with NavBar at the bottom of every
I have created the widget in Jquery mobile for Tabs. I want that when
Suppose I have two pages: - page 1 uses jquery mobile and has a
I have a jquery mobile slider : <input type=range name=slider data-track-theme=c data-highlight=true id=slider-step1 step=10000
I have created one jquery mobile site which having the tab control and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.