2
<div onclick="showCustomerResultsTable();"
 class="csq-tab ui-state-default ui-corner-top"
 id="customers-tab">Customers</div>  

<div onclick="showParcelJourneySummary();"
 class="csq-tab ui-state-default ui-corner-top ui-state-active"
 id="order-journey-summary-tab">Status History</div>

Using javascript how can I check which one of these have ui-state-active, because I need an if statement to check whether the ui-state-active is activated on status history and do something.

3
  • 2
    Are you willing/able to use a Javascript framework such as jQuery? Commented Mar 6, 2012 at 15:51
  • Yes not sure which version i have though Commented Mar 6, 2012 at 15:53
  • 2
    From the class names, I gather that you're already using jQuery UI. jQuery should already be at your disposal... No? Commented Mar 6, 2012 at 15:55

3 Answers 3

3
var statusHistory = document.getElementById('order-journey-summary-tab');

if(statusHistory.classList.contains('ui-state-active')) {
    // do stuff
}

or if you have jQuery

if($('#order-journey-summary-tab').hasClass('ui-state-active')) {
    // do stuff
}
Sign up to request clarification or add additional context in comments.

Comments

3

This can easily be checked with the new HTML5 classList API:

document.getElementById('customers-tab').classList.contains('ui-state-active');
// Will return true if element has class

Otherwise, you'll have to use the old way:

document.getElementById('customers-tab').className.indexOf('ui-state-active') != -1;
// Will return true if element has class

I would recommend using the hasClass() property in jQuery though!

Comments

2

You could use jQuery's hasClass().

Otherwise you need to check the className property of the element w/ plain ol' JavaScript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.