0

I've the following tab elements in my HTML.

<section id="bill-information">
<!-- Tabbed Navigation for bills -->
<ul class="bill-tab-header">
<li class="bill-tab-button bill-tab-button-selected bill-tab-fixed-width"><a href="#tab-1"><span>OPEN</span></a></li>
<li class="bill-tab-button bill-tab-fixed-width"><a href="#tab-2"><span>SETTLED</span></a></li>
<li class="bill-tab-button bill-tab-fixed-width"><a href="#tab-3"><span>CANCEL</span></a></li>
</ul>

There is a separate CSS class for the selected Item. I want to change the Class to the clicked tab. How can I do this using JQuery.

Thank you.

4 Answers 4

2

EXAMPLE

$(function() {

  var selClass= "bill-tab-button-selected";
  $('.bill-tab-header li').click(function( e ) {
    e.preventDefault();
    $(this).addClass(selClass).siblings().removeClass(selClass);
  });

});

http://api.jquery.com/event.preventDefault/
http://api.jquery.com/click/
http://api.jquery.com/addclass/
http://api.jquery.com/siblings/
http://api.jquery.com/removeclass/

Sign up to request clarification or add additional context in comments.

Comments

0

May be its useful for you.

 previouslyClicked = $(".btn").eq(0); //Assuming first tab is selected by default
   $(".btn").click(function () {       
    previouslyClicked.removeClass("course-btn-tab-selected").addClass("course-btn-tab");                 
   $(this).addClass("course-btn-tab-selected");
   previouslyClicked = $(this);           
  });

Comments

0

You can use

$("#btnID").addClass("myClass yourClass");

on click event to add class and to remove class use

$("p").removeClass("myClass noClass")

reference

http://api.jquery.com/addClass/

Comments

0

You can do like this:

$('.bill-tab-button').click(function() {
    $(this).addClass("bill-tab-button-selected").siblings().removeClass('bill-tab-button-selected');
});

Demo

1 Comment

$(".bill-tab-button").each(function() { the .each() method is not needed here at all, cause $(".bill-tab-button") returns a collection of elements already.

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.